打表处理(Case 1超时)
对m进行枚举,每次枚举进行一次判断
因为好人坏人均为k个,那么只要让下一个死亡的人的位置p保证在1~剩余坏人数量之间即可,不满足则直接break枚举下一个m
实际上对于m,因为m必须是 [2kC+1,2kC+k] C∈N+ 之间的数,所以还能再优化,但下面的代码已经能够在78ms左右过题,故可以忽略
#include<stdio.h> int main(){ int s[14],k,m,p,d; for(k=1;k<14;k++){ m=k; while(1){ for(d=p=0;d<k;d++){ p=(p+m-1)%(2*k-d); if(p<k) break; } if(d==k) break; m++; } s[k]=m; } while(scanf("%d",&k)!=EOF) printf("%d\n",s[k]); return 0; }