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