uva 305 - Joseph(暴力)
2014-08-23 23:47
369 查看
题目链接:uva 305 - Joseph
题目大意:给定n,表示2n个人进行约瑟夫环游戏,前n个人为好人,后n个人为坏人,要求一个步长k,保证n个坏人死前没有好人挂掉。
解题思路:枚举步长利用公式递推判断即可。
题目大意:给定n,表示2n个人进行约瑟夫环游戏,前n个人为好人,后n个人为坏人,要求一个步长k,保证n个坏人死前没有好人挂掉。
解题思路:枚举步长利用公式递推判断即可。
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; bool judge (int n, int k) { int pos = 0; for (int i = 2 * n; i > n; i--) { pos = (pos - 1 + k) % i; if (pos < n) return false; } return true; } int solve (int n) { for (int i = n+1; true; i++) if (judge(n, i)) return i; } int main () { int n, ans[15]; for (int i = 1; i <= 14; i++) ans[i] = solve(i); while (scanf("%d", &n) == 1 && n) { printf("%d\n", ans ); } return 0; }
相关文章推荐
- UVA, 305 Joseph
- UVA305 - Joseph(数论 + 打表)
- UVA 305 Joseph (约瑟夫环 打表)
- UVA 305 Joseph
- uva 305 Joseph
- UVa 305 - Joseph
- UVa 305 / POJ 1012 Joseph (如何得到约瑟夫环的下一个位置?)
- uva 305 Joseph
- 约瑟夫循环问题uva305 Joseph
- Uva 305 Joseph(数学+打表)
- UVALive5520 UVA305 POJ1012 HDU1443 Joseph【数学计算+打表+水题】
- UVA 305 Joseph (约瑟夫环 打表)
- UVA 305 - Joseph(模拟)
- Uva 305 - Joseph
- uva305 - Joseph 约瑟夫问题变形
- Joseph - acm.uva.305(约瑟夫环)
- UVA305 - Joseph(数论 + 打表)
- UVA 305 - Joseph
- Uva305——Joseph
- uva 305 Joseph(约瑟夫环解+打表)