UVA11805 Bafana Bafana【模除】

2019-04-14 12:48发布

Team practice is very important not only for programming contest but also for football. By team practice players can learn cooperating with team mates. For playing as a team improvement of passing skill is very important. Passing is a great way of getting the ball upfield and reduces the risk of giving the ball away.
    Carlos Alberto Parreira, the coach of Bafana Bafana, also wants his players to practice passing a lot. That’s why, while in the training camp for soccer world cup 2010, every day he asks all of the players who are present in practice to stand in a circle and practice passing. If N players are in practice, he gives each of the players a distinct number from 1 to N, and asks them to stand sequentially, so that player 2 will stand in right side of player 1 and player 3 will stand in right side of player 2, and so on. As they are in a circle, player 1 will stand right to player N.
    The rule of passing practice is, Parreira will give the ball to player K, and practice will start. Practice will come to an end after P passes. In each pass, a player will give the ball to his partner who is in his immediate right side. After P passes, the player who owns the ball at that moment will give the ball back to Parreira.
    Parreira wants to be ensured that his players practice according the rule. So he wants a program which will tell him which player will give him the ball back. So after taking the ball from the same person he can be happy that, the players play according to the rules. Otherwise he will ask them to start from beginning.
Input
Input starts with an integer T (T ≤ 1000), the number of test cases. Each test case will contain three integers, N (2 ≤ N ≤ 23), K (1 ≤ K ≤ N), P (1 ≤ P ≤ 200).
Output
For each test case, output a single line giving the case number followed by the Bafana player number who will give the ball to Parreira. See sample output for exact format.
Sample Input
3
5 2 5
6 3 5
4 1 3
Sample Output
Case 1: 2
Case 2: 2
Case 3: 4 问题链接UVA11805 Bafana Bafana
问题简述:(略)
问题分析
    n个人围成一圈编号1~n,玩传球游戏,从编号k的人开始,每次传给下一个人,第p次传球到谁。
    围成一圈传递,则是一种循环。循环问题往往可以通过模除来实现,直接模除即可。一个简单数学计算题。
程序说明:(略)
参考链接:(略)
题记:(略) AC的C++语言程序如下: /* UVA11805 Bafana Bafana */ #include using namespace std; int main() { int t, n, k, p, ans; while(~scanf("%d", &t)) for(int i = 1; i <= t; i++) { scanf("%d%d%d", &n, &k, &p); ans = (k + p ) % n; ans = ans ? ans : n; printf("Case %d: %d ", i, ans); } return 0; }