Time
Limit: 2000/1000 MS (Java/Others) Memory Limit:
65536/32768 K (Java/Others)
Total Submission(s):
1512 Accepted Submission(s):
948
1 #include <iostream> 2 using namespace std; 3 int Joseph(int k,int m) 4 { 5 int len = 2*k; 6 int i; 7 int n = 1; //n是要出去的位置,起始位置初始化为1 8 for (i=1;i<=k;i++) 9 { 10 n = (n+m-1)%len; //第i次出去的人 11 if(n==0) //最后一个人出去 12 n = len; 13 if(n<=k) //n小于或等于k时候,返回false 14 return false; 15 len--; //出去一个人,则长度减1 16 } 17 return true; 18 } 19 20 int main() 21 { 22 int a[20]; 23 int i,j; 24 for (i=1;i<15;i++) 25 for(j=i+1;;j++) 26 if (Joseph(i,j)) 27 { 28 a[i] = j; 29 break; 30 } 31 int n; 32 while(cin>>n && n) 33 cout<<a[n]<<endl; 34 return 0; 35 }
Hdu 1443 Joseph,布布扣,bubuko.com
原文:http://www.cnblogs.com/yazhou/p/3639165.html