标签:
南阳oj题目地址:传送门
| 人 | 1 | 2 | 3 | 4 | 3 | 2 | 1 | 2 | 3 |
| 报数 | 1 | 2 | 3 | 4 | 5 | 6 | X | 8 | 9 |
| 人 | 4 | 3 | 2 | 1 | 2 | 3 | 4 | 3 | 2 |
| 报数 | 10 | 11 | 12 | 13 | X | 15 | 16 | X | 18 |
| 人 | 1 | 2 | 3 | 4 | 3 | 2 | 1 | 2 | 3 |
| 报数 | 19 | 20 | X | 22 | 23 | 24 | 25 | 26 | X |
| 人 | 4 | 3 | 2 | 1 | 2 | 3 | 4 | 3 | 2 |
| 报数 | X | 29 | 30 | 31 | 32 | 33 | 34 | X | 36 |
4 3 1 4 3 2 4 3 3 4 3 4 0 0 0
17 21 27 35
第一种思路,直接进行模拟,按照先顺序,后倒序进行模拟
#include <cstdio>
#include <cstring>
/**
判断n是不是7的倍数,或者包含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%d%d",&n,&m,&k)&&n&&m&&k){
int pos=0,count=0,flag=0;
//顺序处理
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;//进行倒序处理
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;//回溯到顺序
}
}
}
return 0;
}
参考博客:http://blog.csdn.net/whjkm/article/details/39830611
ACM--模拟--nyoj 559--报数游戏--湖南第七届省赛
标签:
原文地址:http://blog.csdn.net/qq_26891045/article/details/51428385