Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
63284 | Wuxiang2005 | 选猴王 | C++ | Time Limit Exceeded | 1000 MS | 252 KB | 747 | 2025-03-26 13:07:59 |
#include<bits/stdc++.h> using namespace std; int n,m; int f(int n,int m){ bool isCount[n+1]; int takeSize =0; int index = 1; int cnt = 1; while(1){ if(isCount[index] == true){ index = (index + 1)%(n+1); continue; } if(cnt == m){ cnt = 1; takeSize++; if(takeSize == n-1)break; isCount[index] = true; }else{ cnt++; } index = (index +1)%(n+1); } int ans = -1; for(int i = 1;i<=n;i++)if(isCount[i] == false)return i; return ans; } int main(){ while(1){ cin>>n>>m; if(n == 0 && m == 0)break; cout<<f(n,m)<<endl; } return 0; }