http://poj.org/problem?id=1012

答案以954ms飘过,不过这道题可以轻松用打表过

思路:如果我们把每个人位于数组中的原始编号记为绝对编号,每次循环过后相对于绝对编号为0的人的编号为相对编号,那么在这道题里,绝对编号是不重要的,只需要每次相对编号n都落在n>=k的位置上,那么n轮后自然所有的bad boy都被处理了.

而相对编号的推导:

设 id[i]为第i轮点到的编号(i从1开始计数),第i+1轮开始时存在的人数就会是2*k-i,点到的人的编号就是(id[i]+m-1)%(2*k-i)

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=;
int ans[maxn];
int n,m;
bool judge(){
int t=(m-)%(*n);
for(int i=;i<=n;i++){
if(t<n){return false;}
t=(t+m-)%(*n-i);
}
return true;
}
int main()
{
for(n=;n<maxn;n++){
for(m=n+;;m++){
if(judge()){
ans[n]=m;
break;
}
}
}
while(scanf("%d",&n)==&&n)
printf("%d\n",ans[n]);
return ;
}

最新文章

  1. Linux内核链表深度分析【转】
  2. FineUI疑难杂症
  3. vyos (三) HA
  4. 【BZOJ】【3524】【POI2014】Couriers
  5. Junit 源码剖析(一)
  6. OAuth2.0基本流程
  7. Angular简易分页设计(一):基本功能实现
  8. win10 搜索不能使用解决方法
  9. Liers 树状数组+中国剩余定理
  10. 在 JPA、Hibernate 和 Spring 中配置 Ehcache 缓存
  11. Spring 4.x (一)
  12. CentOS7更换国内源
  13. mysql基本知识点梳理和查询优化
  14. (转)NHibernate+MySql常见问题
  15. Android-多线程安全问题-synchronized
  16. Loadrunner 性能指标
  17. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option)
  18. Linux实战教学笔记38:企业级Nginx Web服务优化实战(下)
  19. Android--真机调试程序方法
  20. maven 安装jar包

热门文章

  1. Git与Repo入门(转载)
  2. 事件冒泡与事件委托 -Tom
  3. poj1673EXOCENTER OF A TRIANGLE
  4. IIS Express简介
  5. MediaPlayer的生命周期
  6. 【Todo】OSGi学习
  7. iOS之UIImagePickerController的应用
  8. supervisord
  9. hdu4418(概率dp + 高斯消元)
  10. codeblock报__objc_class_name_xxx问题