A. Ball Game
来源:互联网 发布:淘宝店店长职责 编辑:程序博客网 时间:2024/05/17 15:41
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to nclockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.
In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
10
2 4 7 1 6 2 9 7 6
3
2 1
解题说明:此题是一个环形传球游戏,类似约瑟夫问题,特点是每次传球时距离增加1,注意一下边界情况即可。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main(){ int n,p=1,c;scanf("%d",&n);for(c=1;c<=n-1;c++){p=p+c;if(p>n){p=p-n;}printf("%d ",p);}printf("\n");return 0;}
- A. Ball Game
- 【字符串计算】#STC 1 A. Ball Game
- 【水循环数组】#43 A. Ball Game
- hdu4605 Magic Ball Game
- 4605 Magic Ball Game
- HDU4605-Magic Ball Game
- Ball Blasting Game UVA
- hdu 4605 Magic Ball Game
- hdu 4605 Magic Ball Game
- hdu 4605 Magic Ball Game
- UVA 12378 Ball Blasting Game
- hdu 4605 Magic Ball Game
- HDU 4605 Magic Ball Game
- hdu4605Magic Ball Game 树状数组
- HDU.4605 Magic Ball Game
- A simple bouncing ball
- ROLL A BALL 小游戏
- A. Jumping Ball
- PLSQL Developer 你用的很方便吗,看看就方便了
- UID, EUID, SUID
- Linux备份与压缩策略
- 修改错误的rc.local文件
- 访问iis元数据库失败
- A. Ball Game
- C++面向对象编程实例——实现学生信息的添加与查询
- C#操作XML配置文件
- Linux 2.6.21 支持Ipv6的裁剪
- GCC编译过程分解
- CF:94A. Restoring Password
- Object-C 协议protocol
- Oracle 查询表字段属性的方法
- iOS网络编程-解决iCloud文档存储过程中文档冲突问题