uva133-S.B.S.
2016-04-05 18:45
246 查看
The Dole Queue |
Input
Write a program that will successively read in (in that order) the three numbers (N, k and m; k, m > 0, 0 < N < 20) and determine the order in which the applicants are sent off for retraining. Each set of three numbers will be on a separate line and the end of data will be signalled by three zeroes (0 0 0).Output
For each triplet, output a single line of numbers specifying the order in which people are chosen. Each number should be in a field of 3 characters. For pairs of numbers list the person chosen by the counter-clockwise official first. Separate successive pairs (or singletons) by commas (but there should not be a trailing comma).Sample input
10 4 3 0 0 0
Sample output
4
8,
9
5,
3
1,
2
6,
10,
7
where
represents a space.
----------------------------------我是分割线--------------------------------------------
这道题简单,上代码:
// UVa133 The Dole Queue #include<cstdio> #define maxn 25 int n, k, m, a[maxn]; int go(int p, int d, int t) { while(t--) { do {p=(p+d+n-1)%n+1;} while(a[p] == 0); } return p; } int main() { while(scanf("%d%d%d", &n, &k, &m) == 3 && n) { for(int i = 1; i <= n; i++) a[i] = i; int left = n; int p1 = n, p2 = 1; while(left) { p1 = go(p1, 1, k); p2 = go(p2, -1, m); printf("%3d", p1); left--; if(p2 != p1) { printf("%3d", p2); left--; } a[p1] = a[p2] = 0; if(left) printf(","); } printf("\n"); } return 0; }
相关文章推荐
- Spring Mvc 笔记二之异常和文件上传
- 第四周 18 设计游戏角色类(2)
- Git学习(五)----Git工作区&暂存区&版本库(“三巨头”)、删除文件、撤销操作
- 第五周 项目二 游戏中的角色类 (2)
- Leetcode 93. Restore IP Addresses
- CMS GC时出现promotion failed跟concurrent mode failure
- 有趣的数
- HDU 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
- 第四周项目17-游戏角色设计(1)
- AOP笔记
- 你的毒舌不是幽默,是没教养
- 通过api欺骗获取安卓应用的启动时间
- Thymeleaf利用layout.html文件生成页面布局框架
- docker中nginx容器和php容器混合运行
- Bootstrap学习笔记—关于网格系统
- zookeeper,CuratorFramework,springMVC整合相关问题
- 重载函数调用运算符()
- 30多个HTML5经典动画应用展示
- View事件面试总结21问21答。
- Process the Tasks(ZOJ3331)