题解 | #删数#
删数
https://www.nowcoder.com/practice/f9533a71aada4f35867008be22be5b6e
#include <iostream> #include <vector> using namespace std; int FindTheLastDeleted(int N) { vector<int> arr; for (int i=0; i<N; i++){ arr.push_back(i); } int index = 0; while(arr.size()>1){ index = ((index + 2) % arr.size()); arr.erase(arr.begin()+index); } return arr[0]; } int main() { int N; while (cin >> N) { // 注意 while 处理多个 case cout<<FindTheLastDeleted(N)<<endl; } return 0; } // 64 位输出请用 printf("%lld")