ACM-simulation-nyoj 559-Report game-Hunan seventh provincial Competition

Source: Internet
Author: User


Nanyang OJ subject address: Portal


Game time limit: 1000 MS | memory limit: 65535 kb difficulty: 2
Description
N people stand in one row to play a report game. The numbers of all users are 1 to n from left to right. At the beginning of the game, the leftmost people reported 1, the people on the right reported 2, The people numbered 3 reported 3, and so on. After N is reported, the person on the left (I .e., the person on the rightmost) Reports n + 1, then the person numbered N-2 reported n + 2, and so on. When the leftmost person reports the number again, the report direction changes from left to right, and so on. To prevent games from getting bored, there is a special case when reporting: if the number should contain a number 7 or a multiple of 7, he should replace the number with a clap. The following table lists the numbers of N = 4 (X indicates a clap ). When a person with the number 3 clap his hands for 4th times, the number actually reaches 35.
Person 1 2 3 4 3 2 1 2 3
Reports 1 2 3 4 5 6 X 8 9
Person 4 3 2 1 2 3 4 3 2
Reports 10 11 12 13 X 15 16 X 18
Person 1 2 3 4 3 2 1 2 3
Reports 19 20 X 22 23 24 25 26 X
Person 4 3 2 1 2 3 4 3 2
Reports X 29 30 31 32 33 34 X 36

Given n, m, and K, your task is to calculate the number of a person with the number of M to the number of K clap operations.
Input
The input contains no more than 10 groups of data. Each group of data occupies one row and contains three integers, n, m, and K (2 <= n <= 100, 1 <= m <= n, 1 <= k <= 100 ). The input end flag is n = m = k = 0.
Output
For each group of data, a row is output, that is, the integer to which a person numbered m actually counts when he clap his hands for the K time.
Sample Input
4 3 1 4 3 2 4 3 3 4 3 4 0 0 0 
Sample output
17 21 27 35 



The first approach is to directly simulate the process, first in order, and then in reverse order.


# Include <cstdio> # include <cstring>/** determines whether N is a multiple of 7 or contains 7 */bool judge (int n) {If (! (N % 7) return true; while (n) {If (N % 10 = 7) return true; N/= 10;} return false;} int main () {int n, m, K, I; while (scanf ("% d", & N, & M, & K) & N & M & K) {int Pos = 0, Count = 0, flag = 0; // sequential processing for (I = 1; I <= N; I ++) {pos ++; if (I = m) {If (Judge (POS) Count ++; // If (COUNT = k) {printf ("% d \ n", POS); break ;}} if (I = N) {I = n-1; // perform reverse processing for (; I> = 1; I --) {pos ++; if (I = m) {If (Judge (POS) Count ++; If (COUNT = k) {flag = 1; printf ("% d \ n", POS ); break ;}}if (FLAG) break; I = 1; // trace back to order }}} return 0 ;}



Reference blog: http://blog.csdn.net/whjkm/article/details/39830611


ACM-simulation-nyoj 559-Report game-Hunan seventh provincial Competition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.