hdu_2925_Musical Chairs_201311121643
Musical Chairs
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 898 Accepted Submission(s): 509
For example, consider the game illustrated in the figure above for N = 5 and D = 3 . In the figure, the dot indicates where counting starts and × indicates the child leaving. Starting off, child #3 leaves the game, and counting restarts with child #4. Child #1 is the second child to leave and counting restart with child #2 resulting in child #5 leaving. Child #2 is the last to leave, and child #4 is the winner. Write a program to determine the winning child given both N and D .
The last line of the input file contains two 0's and is not part of the test cases.
N D W
Where N and D are as above, is a space character, and W is the winner of that game.
#include <stdio.h>
int main()
{
int n,d;
while(scanf("%d %d",&n,&d),n||d)
{
int i,w=;
for(i=;i<=n;i++)
w=(w+d)%i;
printf("%d %d %d\n",n,d,w+);
}
return ;
}
约瑟夫环问题:
http://baike.baidu.com/link?url=DLfL-nqyyQmoxRRs7ZnN6NxV2wAX1FDDT2I0kboKxbSK95NzWRx2ITNsgjrUw13W
数学方法
hdu_2925_Musical Chairs_201311121643的更多相关文章
随机推荐
- [Swift通天遁地]五、高级扩展-(13)图片资源本地化设置:根据不同的语言环境显示不同语言版本图片
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]九、拔剑吧-(16)搭建卡片页面:Card Peek/Pop动态切换界面
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Vue项目中如何使用less(添加less依赖)
今天在新工程里添加了一段样式代码代码突然报错了: <!-- Add "scoped" attribute to limit CSS to this component onl ...
- SQLServer局部变量和全局变量介绍05-29学习笔记
变量 数据在内存中存储可以变化的量叫变量.为了在内存中存储信息,用户必须指定存储信息的单元,并为了该存储单元命名, 以方便获取信息,这就是变量的功能.Transact-SQL可以使用两种变量,一种是局 ...
- Jsoup爬虫获取公司纳税识别号
天眼查 /** * 根据公司名称获取统一社会信用代码 * * @author xiaofei.xian 日期:2019年3月20日 上午11:12:41 */ public class GetTaxN ...
- [转]linux sudo 命令
转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/11/11/2245341.html “Sudo”是Unix/Linux平台上的一个 ...
- Java_注解之一
注解可以替换复杂的hbm.xml文件,使得程序的开发大大简化 @Override :子类重写父类方法 @Test :junit测试 @Before :测试之前执行 @SuppressWarnin ...
- 9.Hierarchy Editor
Hierarchy Editor(层次编辑器) 用于定义3D图层的结构,向Ventuz渲染引擎发出“命令”,并指定命令的发生顺序.通常,每个层次节点都会导致对GPU的一个或多个调用,例如设置材质或渲染 ...
- [ HNOI 2006 ] 公路修建问题
\(\\\) \(Description\) 一个\(N\)个点\(M\)条边的图,每条边可以选择\(w_i,p_i\)两个边权之一,现求一个生成树上的最大边权最小值,要求这棵生成树上至少有\(K\) ...
- [ 51Nod 1327 ] 棋盘游戏
\(\\\) \(Description\) 给出一张\(N\times M\)的棋盘,每个格子最多放置一个棋子,一个合法的放置方案需满足: 每列至多放置一个棋子 对于第\(i\)行,前\(L_i\) ...