Files
python/TangDou/XiTi/1377.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

39 lines
870 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/**
*
样例输入: 1 100
28 5437
样例输出: 418
900585
* @return
*/
int main() {
int a, n;
cin >> a >> n;
//双队列,不让重复数据出现是关键,黄海第一次作此题时就犯了错误,使用map去重,就非常麻烦了,因为map的长度不好控制
queue<int> q1;
queue<int> q2;
int k = 1;
while (k < n) {
q1.push(a * 2 + 1);
q2.push(a * 3 + 1);
if (q1.front() < q2.front()) {
a = q1.front();
q1.pop();
} else if (q1.front() > q2.front()) {
a = q2.front();
q2.pop();
} else {
a = q1.front();
q1.pop();
q2.pop();
}
k++;
}
cout << a << endl;
return 0;
}