poj 3750

来源:互联网 发布:快速出效果图软件 编辑:程序博客网 时间:2024/06/01 21:39

约瑟夫问题

#include <iostream>#include <cstdio>#include <cstring>const int maxn = 55;const int maxl = 20;using namespace std;char name[maxn][maxl];bool flag[maxn];int main(){    int n;    while(~scanf("%d",&n)){          memset(flag,false,sizeof(flag));          for(int i = 0; i < n; ++i)             scanf("%s",name[i]);          int cnt = 0;          int s,m;          scanf("%d,%d",&s,&m);          s--;          while(cnt != n){              int c = 0;              while(true){                   if(!flag[s%n])                      c++;                   if(c == m) break;                   s++;              }              cnt++;              flag[s%n] = true;              printf("%s\n",name[s%n]);          }    }    return 0;}


 

原创粉丝点击