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的更多相关文章
随机推荐
- 网页分享URL
<a href="tencent://Message/?Uin=QQ号码&Site=qq联系">点击联系</a> 1.新浪微博:<a href ...
- win10系统下,开启数据库远程连接方式
右键左下角的windows标志,选择控制面板 2.查看方式修改为大图标 3.选择高级设置 4.新建入站规则 5.选择端口然后下一步 6.选择tcp协议,端口输入80,3306 7.选择允许连接 8.规 ...
- Rails 拉数据初始数据库
rails c [1] pry(main)> Scraping.exec
- [Swift通天遁地]六、智能布局-(1)给视图添加尺寸和中心点的约束
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Linux-fork()函数详解,附代码注释
// // main.c // Project_C // // Created by LiJinxu on 16/8/13. // Copyright © 2016年 LiJinxu-NEU. All ...
- 百度之星2017初赛B1006 小小粉丝度度熊
思路: 考虑到补签卡一定是连续放置才更优,所以直接根据起始位置枚举.预先处理区间之间的gap的前缀和,在枚举过程中二分即可.复杂度O(nlog(n)). 实现: #include <iostre ...
- js基础---元素操作时字符串拼接
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 前端开发之旅- 移动端HTML5实现文件上传
一. 在一个客户的webapp项目中需要用到 html5调用手机摄像头,找了很多资料,大都是 js调用api 然后怎样怎样,做了几个demo测试发现根本不行, 后来恍然大悟,用html5自带的 in ...
- JS——动态添加事件和移除事件(有待补充...)
动态的添加事件:利用 attachEvent 和 addEventListener IE 支持 attachEvent: obj.attachEvent("onclick", Fo ...
- THREE.js代码备份——webgl - geometry - dynamic(模拟海浪,通过时间(毫秒)来控制平面点的运动模拟海浪,鼠标控制写在另外的js中)
HTML: <!DOCTYPE html> <html lang="en"> <head> <title>three.js webg ...