Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
2016-01-16 18:18
405 查看
Another Rock-Paper-Scissors Problem
题目连接:
http://codeforces.com/gym/100015/attachmentsDescription
Sonny uses a very peculiar pattern when it comes to playing rock-paper-scissors. He likes to vary his movesso that his opponent can’t beat him with his own strategy.
Sonny will play rock (R) on his first game, followed by paper (P) and scissors (S) for his second and
third games, respectively. But what if someone else is using the same strategy? To thwart those opponents,
he’ll then play paper to beat rock, scissors to beat paper, and rock to beat scissors, in that order, for his 4th
through 6th games. After that, he’ll play scissors, rock, and paper for games 7–9 to beat anyone copying
his last set of moves. Now we’re back to the original order—rock, paper, scissors—but instead of being
predictable and using the same moves, do you know what would be better? You guessed it! Sonny then
plays the sequence of moves that would beat anyone trying to copy his whole strategy from his first move,
and on it goes...
To recap, in symbolic form, Sonny’s rock-paper-scissors moves look like this:
RPSPSRSRPPSRSRPRPSSRPRPSPSRPSRSRPRPSSRPRPSPSRRPSPSRSRP ...
The spaces are present only to help show Sonny’s playing pattern and do not alter what move he’ll play on
a certain game.
Naturally, your job is to beat Sonny at his own game! If you know the number of the game that you’ll
be playing against Sonny, can you figure out what move you would need to play in order to beat him?
Input
Each line of the input contains a single integer N,1 ! N ! 1012, the number of the game you’ll be playingagainst Sonny. An integer N = 1 indicates it would be Sonny’s first game, N = 7 indicates it would be the
7th game, and so forth. The input terminates with a line with N = 0. For example:
1
7
33
0
Warning: N may be large enough to overflow a 32-bit integer, so be sure to use a larger data type (i.e.
long in Java or long long in C/C++) in your program.
Output
For each test case, output a single line which contains the letter corresponding to the move you would needto play to beat Sonny on that game. For example, the correct output for the sample input above would be:
P
R
S
Sample Input
17
33
0
Sample Output
PR
S
Hint
题意
剪刀石头布初始串,RPS
每次操作如下:设现在的串为S
1、将之前的串全部击败,得到S'
2、将S'打败,然后得到S''
然后给你第i位,然后输出打败第i位的策略
题解:
找找规律之后会发现,这个串类似于3进制一样的比如说23,他是23->14->5->2这样过来的
然后我们只用算他是从哪儿过来的,迭代了几次就好了
代码
#include<bits/stdc++.h> using namespace std; const long long limit = 1000000000050LL; vector<long long> three; string solve(long long n,long long step) { if(n==1) { if(step%3==0) return "P"; else if(step%3==1) return "S"; else return "R"; } if(n==2) { if(step%3==0) return "S"; else if(step%3==1) return "R"; else return "P"; } if(n==3) { if(step%3==0) return "R"; else if(step%3==1) return "P"; else return "S"; } } int main() { long long k = 3; for(int i=0;;i++) { three.push_back(k); k*=3; if(k>limit) break; } long long n; while(cin>>n) { if(n==0)break; int step = 0; while(n>3) { n-=*--lower_bound(three.begin(),three.end(),n); step++; } cout<<solve(n,step)<<endl; } }
相关文章推荐
- 线程间互斥
- 蓝懿IOS/UINavigationController
- 手把手教你把Vim改装成一个IDE编程环境(图文)
- FPGA开发中的脚本语言
- C++编程中break语句和continue语句的学习教程
- 2. Add Two Numbers 给定的两个链表是逆序排列的,相加后放在一个新的链表里边
- linux运维实战练习案例-2015年12月20日-12月31日
- java数组的理解--学习总结
- TableView遇到的问题
- 编程修养
- WINDOWS下的目录映射工具(微软官方工具)
- 水题
- UESTC-- 1263
- 迪米特法则学习笔记
- 数据结构_7:图算法 :图的最小生成树
- Dplasma调度方式—— DAGUE_SCHEDULER_AP(Absolute priorities)
- 专业课第二章知识总结
- 第1周:指针与字符串
- JavaSE-可变个数的形参
- Android同一设备DPI数值大小与显示大小的关系