POJ 1012 Joseph
来源:互联网 发布:阿里巴巴双十一数据 编辑:程序博客网 时间:2024/06/05 19:03
The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6 and m = 5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved.
Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy.
Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy.
The input file consists of separate lines containing k. The last line in the input file contains 0. You can suppose that 0 < k < 14.
The output file will consist of separate lines containing m corresponding to k in the input file.
340
530
打表
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int res[15];void Init(){ int sum; for(int k=1;k<14;k++) for(int m=k+1;;m++){ sum=k*2; int flag=0; for(int j=m;;j+=m-1){ j=j%sum?j%sum:sum; if(j<=k) break; sum--; if(sum==k){ flag=1; break; } } if(flag){ res[k]=m; break; } }}int main(){ Init(); int k; while(~scanf("%d",&k) && k){ printf("%d\n",res[k]); } return 0;}
阅读全文
0 0
- POJ 1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- 【POJ】1012 Joseph
- poj 1012 Joseph
- poj-1012 Joseph
- POJ 1012 Joseph
- poj 1012 Joseph
- Poj 1012 Joseph
- POJ - 1012 Joseph
- [POJ][1012]Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph
- POJ 1012 Joseph(打表题)
- selenium3.x 踏坑记
- 【dijkstra + 优先队列 && bfs && A*】POJ
- somnic各应用下载目录
- web.xml 中的listener、 filter、servlet 加载顺序及其详解
- LA 3720 Highway n x m的点阵 有多少条直线穿过至少2个点
- POJ 1012 Joseph
- Max Sum Plus Plus HDU
- mysql索引的长度问题
- 【VS】控制台程序,更改系统默认图标。
- 微信小程序开发(5)-新闻页之滚动制作(scroll-view)组件的使用
- DDL-数据定义语言
- Gerrit日常操作命令收集
- 使用git管理代码,mac看不到生成的.git文件
- 算法第四版 练习1.3.35