标签:io os sp for 代码 ad amp size as
题意:约瑟夫环的变形,要求寻找到一个杀人循环节m使后半节的坏人先被全部杀光。
直接链表模拟出结果,再打表就行;
代码:(注释的是打表码)
#include<iostream> #include<cstdio> #include<cmath> #include<map> #include<queue> #include<string> #include<cstring> #include<algorithm> using namespace std; /* int l[30],r[30]; int main() { int k=1; //while(~scanf("%d",&k)&&k) for(k=1;k<14;k++) { k*=2;int ans=0; for(int i=1;1;i++) { memset(r,0,sizeof r); memset(l,0,sizeof l); for(int j=1;j<=k;j++) r[j]=j+1,l[j]=j-1; r[k]=1;l[0]=k; int dead=0,flag=1; for(int num=1,x=1;dead!=k/2;x=r[x],num++) { if(num!=i) if((i-num)/(k-dead)&&(i-num)%(k-dead)>0)num+=(i-num)/(k-dead)*(k-dead); else ; else if(x>k/2)num=0,l[r[x]]=l[x],r[l[x]]=r[x],dead++; else {flag=0;break;} } if(flag){ans=i;break;} } printf("%d,",ans); k/=2; } return 0; } */ int da[]={2,7,5,30,169,441,1872,7632,1740,93313,459901,1358657,2504881}; int main() { int n; while(~scanf("%d",&n)&&n) { printf("%d\n",da[n-1]); } return 0; }
标签:io os sp for 代码 ad amp size as
原文地址:http://blog.csdn.net/u014569598/article/details/40979081