解题思路:
注意事项:
参考代码:
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdio.h> using namespace std; int solve(int n) { vector<int> str; for (int i = 1; i <= n; i++) str.push_back(i); int index = 0; vector<int>::iterator it = str.begin(); while (str.size() > 1) { index = (index + 2)%str.size(); it = str.begin() + index; it = str.erase(it); index = it - str.begin(); } return str.at(0); } int main(void) { int n = 0; cin >> n; cout << solve(n) << endl; return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题1.6 (C++代码)浏览:889 |
妹子杀手的故事 (C语言代码)浏览:1218 |
WU-整除问题 (C++代码)浏览:611 |
【计算球体积】 (C语言代码)浏览:1101 |
求圆的面积 (C语言代码)浏览:1667 |
数对 (C语言代码)浏览:697 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:511 |
The 3n + 1 problem (C语言代码)浏览:501 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:984 |
发工资咯 (C语言代码)浏览:792 |