UVA 133 The Dole Queue
来源:互联网 发布:手机淘宝怎么看信誉度 编辑:程序博客网 时间:2024/05/29 16:42
题目
救济金发放
分析
双向约瑟夫环问题。
思路
链表不一定要指针实现,以下是数组模拟。
代码
#include <cstdio>#define N 20int main(){ int n, k, m; int app[N+5]; while (scanf("%d%d%d", &n, &k, &m), n, k, m) { k = (k % n) ? k % n : n; m = (m % n) ? m % n : n; for (int i = 1; i <= n; i++) app[i] = i; int ki = n, mi = 1; while (1) { for (int i = k; i > 0; i--) { if (ki == n) ki = 1; /* 回环 */ else ki++; if (app[ki] == 0) i++; } for (int i = m; i > 0; i--) { if (mi == 1) mi = n; /* 回环 */ else mi--; if (app[mi] == 0) i++; } if (ki == mi) { int a = 0; for (int i = 1; i <= n; i++) if (app[i] != 0) a++; if (a == 1) { printf("%3d\n", ki); break; } else { printf("%3d,", ki); } } else { int b = 0; for (int i = 1; i <= n; i++) if (app[i] != 0) b++; if (b == 2) { printf("%3d%3d\n", ki, mi); break; } else { printf("%3d%3d,", ki, mi); } } app[ki] = app[mi] = 0; } } return 0;}
0 0
- UVa 133 The Dole Queue
- Uva 133 The Dole Queue
- uva 133 - The Dole Queue
- uva-133 - The Dole Queue
- UVa 133 - The Dole Queue
- uva 133 The Dole Queue
- UVa 133 - The Dole Queue
- UVa 133 - The Dole Queue
- uva 133 - The Dole Queue
- uva-133 The Dole Queue
- UVA 133 The Dole Queue
- UVa 133 - The Dole Queue
- uva 133 - The Dole Queue
- uva 133 The Dole Queue
- UVa 133 The Dole Queue
- uva 133 - The Dole Queue
- uva 133 - The Dole Queue
- UVa 133 - The Dole Queue
- 天才的大三暑假修行之旅.表面着色器(总结)
- UVA 101 The Blocks Problem
- bearlon的HTML学习笔记1
- 设计模式(15) - 备忘录模式
- oracle启动脚本——window
- UVA 133 The Dole Queue
- 如何成为SAP行业专家
- 表达式计算 .
- 安卓sqlite数据库加速写入
- 3.03-while练习2
- 第十天 线程
- 关于成为sap顾问的心得体会
- 3.04-while练习3
- 3.05-while注意点