There are n people standing in a line, playing a famous game called counting". When the game begins, the leftmost person says
1" loudly, then the second person (people are numbered 1 to n from left to right) says 2" loudly. This is followed by the 3rd person saying
3" and the 4th person say 4", and so on. When the n-th person (i.e. the rightmost person) said
n" loudly, the next turn goes to his immediate left person (i.e. the (n - 1)-th person), who should say n + 1" loudly, then the (n - 2)-th person should say
n + 2" loudly. After the leftmost person spoke again, the counting goes right again.
There is a catch, though (otherwise, the game would be very boring!): if a person should say a number who is a multiple of 7, or its decimal representation contains the digit 7, he should clap instead! The following tables shows us the counting process for n = 4(`X’ represents a clap). When the 3rd person claps for the 4th time, he’s actually counting 35.
Given n, m and k, your task is to find out, when the m-th person claps for the k-th time, what is the actual number being counted.
Input
There will be at most 10 test cases in the input. Each test case contains three integers n, m and k
(2 ≤ n ≤ 100, 1 ≤ m ≤ n, 1 ≤ k ≤ 100) in a single line. The last test case is followed by a line with
n = m = k = 0, which should not be processed.
Output
For each line, print the actual number being counted, when the m-th person claps for the k-th time. If
this can never happen, print ‘-1’.
Sample Input
4 3 1
4 3 2
4 3 3
4 3 4
0 0 0
Sample Output
17
21
27
35
题意:第一个人喊1,第二个人喊2,第三个人喊3,按顺序接着喊,直到n个人喊完之后,倒数第二个人接着往上喊,倒数第三个接着喊,喊到第一个人之后,第二个人接着喊,也就是说在第一个和最后一个不重复,。若是某个人喊到7或者含有7的不喊或者鼓掌,问你第m个人鼓掌k次之后总数喊到多少了。
思路:2*n-2一个循环,然后进行判断即可。
#include"cstdio"
#include"iostream"
#include"cstring"
#include"algorithm"
using namespace std;
#define manx 1000005
int zml(int x)
{
if(x%7==0)
{
return 1;
}
while(x)
{
if(x%10==7)
{
return 1;
}
x/=10;
}
return 0;
}
int main()
{
int n,m,k,a[1005];
while(~scanf("%d %d %d",&n,&m,&k))
{
if(n==0&&m==0&&k==0)
{
break;
}
else
{
for(int i=1;i<=n;i++)
{
a[i]=i;
}
int t=n-1;
for(int i=n+1;i<=2*n-2;i++)
{
a[i]=t;
t--;
}
int sum=0,i;
for(i=1;i<manx;i++)
{
if(zml(i)==1)
{
if(i%(2*n-2)==0)
{
if(a[2*n-2]==m)
{
sum++;
}
}
else
{
if(a[i%(2*n-2)]==m)
{
sum++;
}
}
}
if(sum==k)
{
printf("%d\n",i);
break;
}
}
if(i==manx)
{
printf("-1\n");
}
}
}
return 0;
}