acm--simulation--nyoj 559----Hunan seventh session of the Provincial game

Source: Internet
Author: User
Tags printf time limit


Nanyang OJ Title address: Portal


Game time limit: Ms | Memory limit: 65535 KB Difficulty: 2 Description n Individuals stand in a row to play a count game. All people are numbered 1 to n from left to right. At the beginning of the game, the leftmost person reported 1, the person on his right is 2, the person with the number 3 is 3, and so on. When the person whose number is n (i.e. the right-most person) has finished n, the person whose turn is on his left (that is, the person numbered n-1) is reported to N+1, then the person who is numbered n-2 n+2, and so on.     When the leftmost person again counted off, the direction of the count turned from left to right, and so on. In order to prevent the game is too boring, there is a special case: if the number should be reported to include the number 7 or a multiple of 7, he should use clap instead of counting. The following table shows the status of N=4 (X for clapping). When the person with the number 3 clapped his hands for the 4th time, he actually counted to 35.

People 1 2 3 4 3 2 1 2 3
Count 1 2 3 4 5 6 X 8 9
People 4 3 2 1 2 3 4 3 2
Count 10 11 12 13 X 15 16 X 18
People 1 2 3 4 3 2 1 2 3
Count 19 20 X 22 23 24 25 26 X
People 4 3 2 1 2 3 4 3 2
Count X 29 30 31 32 33 34 X 36

Given N,m and K, your task is to count the number of people who have been numbered m for the first time, and he actually counted several. The input input contains no more than 10 sets of data. One row for each group of data, containing 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 set of data, the output line, that is, the person numbered m of the first k clap, he actually counted the integer. Sample input
4 3 1 
4 3 2 
4 3 3 
4 3 4 
Sample output
 
35 



The first way of thinking, direct simulation, in order, after the reverse of the simulation


#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% = = 7) return true;
    n/= 10;
} return false;
    } int main () {int n,m,k,i;
        while (scanf ("%d%d%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++;
                   Search results for if (count==k) {printf ("%d\n", POS);
                Break
                    }} if (I==n) {i=n-1;//in 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;//back to Order}}} return 0;
 }



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


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.