求用list怎么解
2024-08-13 09:54:59
发布于:北京
31阅读
0回复
0点赞
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
int main() {
freopen("apple.in", "r",stdin);
freopen("apple.out", "w", stdout);
int n;
cin >> n;
list<int> b;
for (int i = 1; i <= n; i++) {
b.push_back(i);
}
int d = 0;
int db = 0;
bool flag = false;
while (!b.empty()) {
++d;
list<int> bb;
int x = 1;
for (auto it = b.begin(); it != b.end(); ) {
if (x % 3 == 1) {
if (*it == n) {
db = d;
flag = true;
}
it = b.erase(it);
} else {
bb.push_back(*it);
++it;
}
++x;
}
b = bb;
}
cout << d << " " << db << endl;
fclose(stdin);
fclose(stdout);
return 0;
}
全部评论 1
的数据你去模拟?
2024-08-31 来自 广东
0
有帮助,赞一个