报数游戏
2014-11-22 20:58
323 查看
切切水水的~
1251: 报数游戏
Time Limit: 1 Sec Memory Limit:
128 MB
[Submit][Status][Web
Board]
为了防止游戏太无聊,报数时有一个特例:如果应该报的数包含数字7或者是7的倍数,他应当用拍手代替报数。下表是n=4的报数情况(X表示拍手)。当编号为3的人第4次拍手的时候,他实际上数到了35。
给定n,m和k,你的任务是计算当编号为m的人第k次拍手时,他实际上数到了几。
题意很简单,但是处理起来不是很方便~
1251: 报数游戏
Time Limit: 1 Sec Memory Limit:
128 MB
[Submit][Status][Web
Board]
Problem 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。
给定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 1 4 3 2 4 3 3 4 3 4 0 0 0
Sample Output
17 21 27 35
HINT
Source
湖南省第七届大学生程序设计大赛Difficulty
Author
admin题意很简单,但是处理起来不是很方便~
#include <stdio.h> #include <string.h> #include <iostream> #include <math.h> #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack> #define PI acos(-1.0) #define eps 1e-8 #define LL long long #define moo 31536000 #define INF 1e9 #define maxn 150 using namespace std; int first_[maxn]; int next_[maxn]; int ans[maxn]; int cc; int n,m,k; int pp(int x) { int aa=0; while(x) { aa=x%10; x/=10; if(aa==7) break; } if(aa==7) return 1; return 0; } int main() { // cout<<pp[17]<<endl; while(~scanf("%d%d%d",&n,&m,&k) && n) { for(int i=1;i<n;i++) first_[i]=i; for(int i=1;i<n;i++) next_[i]=n-i+1; first_[0]=first_[n-1]; next_[0]=next_[n-1]; cc=0; memset(ans,0,sizeof(ans)); for(int i=1;i<=1000000;i++) { if(cc>=k) break; if(pp(i) || i%7==0) { if(((i+n-2)/(n-1))%2) { if(first_[i%(n-1)]==m) { ++cc; ans[cc]=i; } } else if(next_[i%(n-1)]==m) { ++cc; ans[cc]=i; } } } cout<<ans[k]<<endl; } return 0; } /************************************************************** Problem: 1251 User: mangogo Language: C++ Result: Accepted Time:0 ms Memory:1440 kb ****************************************************************/
相关文章推荐
- CSU1101-报数游戏-模拟、枚举
- 算法:模拟法(报数游戏)
- CCF Java 报数游戏循环剔除类问题
- csdn英雄会(pongo)题解之报数游戏2--源代码
- 算法设计与分析:第二章 递归 2.4报数退圈游戏
- 报数游戏
- nyist559 报数游戏
- 链表实现123报数游戏
- 报数游戏 有n个孩子站成一圈,从第一个孩子开始顺时针方向报数,报到3的人出列,下一个人继续从1报数, 直到最后剩下一个孩子为止。问剩下第几个孩子。
- 报数游戏
- 一直报数游戏
- 报数游戏(3)--【英雄会】
- Linux环境下C语言实现报数游戏
- 报数游戏-(容斥+二分)
- csu-1101: 报数游戏
- 湖南第七届省赛 报数游戏
- 计蒜客 奇怪的报数游戏(树状数组+二分+思路)
- 报数游戏
- 报数游戏 湖南省第七届省赛
- java 报数游戏:有n个孩子站成一圈,从第一个孩子开始顺时针方向报数,报到m的人出列