题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1101
题 意:找出第m个人第k次拍手时,所代表的数字。
思 路:找出计算的规律,本题中从m到n再回来应加上2*(n-m),到开始的位置再回来应加上2*(n-1)。
注:要注意n=m与m==1的情况,不要重复计算。
代码如下:
#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
int judge( int x )
{
if( x%7 == 0 ) return 0;
while( x )
{
int t = x%10;
if( t == 7 ) return 0;
x/=10;
}
return 1;
}
int main()
{
int n, m, k;
while( scanf ( "%d %d %d", &n, &m, &k ) != EOF )
{
if( n == 0 && m == 0 && k == 0 ) break;
int now = m;
if(!judge(now))
{
k--;
if(!k) printf("%d\n",now);
}
for( int i = 2; k >= 1; i ++ )
{
if(i%2==1)
{
if(m!=1)
now += 2*(m-1);
else continue;
}
else
{
if(n!=m)
now += 2*(n-m);
else continue;
}
if(!judge(now)) k--;
}
printf("%d\n",now);
}
return 0;
}