CSU1101-报数游戏-模拟、枚举

来源:互联网 发布:二六三网络通信 编辑:程序博客网 时间:2024/05/16 07:19

M: 报数游戏

Description

n个人站成一行玩一个报数游戏。所有人从左到右编号为1到n。游戏开始时,最左边的人报1,他右边的人报2,编号为3的人报3,等等。当编号为n的人(即最右边的人)报完n之后,轮到他左边的人(即编号为n-1的人)报n+1,然后编号为n-2的人报n+2,以此类推。当最左边的人再次报数之后,报数方向又变成从左到右,依次类推。

为了防止游戏太无聊,报数时有一个特例:如果应该报的数包含数字7或者是7的倍数,他应当用拍手代替报数。下表是n=4的报数情况(X表示拍手)。当编号为3的人第4次拍手的时候,他实际上数到了35。

img

给定n,m和k,你的任务是计算当编号为m的人第k次拍手时,他实际上数到了几。

Input

输入包含不超过10组数据。每组数据占一行,包含三个整数n,m和k(2<=n<=100, 1<=m<=n, 1<=k<=100)。输入结束标志为n=m=k=0。

Output

对于每组数据,输出一行,即编号为m的人第k次拍手时,他实际上数到的那个整数。

Sample Input

4 3 14 3 24 3 34 3 40 0 0

Sample Output

17212735

数据又不大,当然是直接暴力枚举啦~
简单的,暴力的方式简单点

#include <bits/stdc++.h>#define N 10100#define INF 0x3f3f3f3f#define LL long long#define mem(a,n) memset(a,n,sizeof(a))#define fread freopen("in.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;bool have7(int n){    if(n%7==0){        return true;    }int temp;    while(n){        temp=n%10;        n/=10;        if(temp==7){            return true;        }    }    return false;}int main(){     ios::sync_with_stdio(false);    int n,m,k,pos,cnt,a,num;    while(cin>>n>>m>>k&&(n||m||k)){        pos=1,cnt=0,num=a=1;        while(cnt<k){            pos+=a;            num++;            if(pos==m&&have7(num)){                ++cnt;            }            if(pos==n||pos==1){                a=-a;            }        }        cout<<num<<endl;    }    return 0;}/**********************************************************************    Problem: 1101    User: CSUzick    Language: C++    Result: AC    Time:0 ms    Memory:1688 kb**********************************************************************/
原创粉丝点击