Another Rock-Paper-Scissors Problem

题目连接:

http://codeforces.com/gym/100015/attachments

Description

Sonny uses a very peculiar pattern when it comes to playing rock-paper-scissors. He likes to vary his moves

so 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 playing

against 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 need

to play to beat Sonny on that game. For example, the correct output for the sample input above would be:

P

R

S

Sample Input

1

7

33

0

Sample Output

P

R

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;
}
}

Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律的更多相关文章

  1. Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  2. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  3. Gym - 101667H - Rock Paper Scissors FFT 求区间相同个数

    Gym - 101667H:https://vjudge.net/problem/Gym-101667H 参考:https://blog.csdn.net/weixin_37517391/articl ...

  4. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  5. FFT(Rock Paper Scissors Gym - 101667H)

    题目链接:https://vjudge.net/problem/Gym-101667H 题目大意:首先给你两个字符串,R代表石头,P代表布,S代表剪刀,第一个字符串代表第一个人每一次出的类型,第二个字 ...

  6. SDUT 3568 Rock Paper Scissors 状压统计

    就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m ...

  7. Gym101667 H. Rock Paper Scissors

    将第二个字符串改成能赢对方时对方的字符并倒序后,字符串匹配就是卷积的过程. 那么就枚举字符做三次卷积即可. #include <bits/stdc++.h> struct Complex ...

  8. 【题解】CF1426E Rock, Paper, Scissors

    题目戳我 \(\text{Solution:}\) 考虑第二问,赢的局数最小,即输和平的局数最多. 考虑网络流,\(1,2,3\)表示\(Alice\)选择的三种可能性,\(4,5,6\)同理. 它们 ...

  9. 题解 CF1426E - Rock, Paper, Scissors

    一眼题. 第一问很简单吧,就是每个 \(\tt Alice\) 能赢的都尽量让他赢. 第二问很简单吧,就是让 \(\tt Alice\) 输的或平局的尽量多,于是跑个网络最大流.\(1 - 3\) 的 ...

随机推荐

  1. Delphi 提示在Delphi的IDE中,按Ctrl+Shift+G键可以为一个接口生成一个新的GUID。

    对于Object Pascal语言来说,最近一段时间最有意义的改进就是从Delphi3开始支持接口(interface),接口定义了能够与一个对象进行交互操作的一组过程和函数.对一个接口进行定义包含两 ...

  2. 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题

    问题背景: 在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetime类型的数据在转为字符 ...

  3. selenium webdriver+windows+python+chrome遇见的问题

    win7系统,在python中调用ChromeDriver 一直报错 “ selenium.common.exceptions.WebDriverException: Message: 'Chrome ...

  4. bzoj1193

    #include<cstdio> #include<cstdlib> #include<algorithm> #include<queue> using ...

  5. oracle 数据库远程导出

    exp 用户名/密码@IP:端口/数据库名 file=文件路径 full=y; exp scebm1/ebm@10.3.10.16:1521/scebm file=D:scebm20140527.dm ...

  6. JQuery Mobile移动Web应用开发(1): UI开发工具RID介绍

    工欲善其事,必先利其器. UI工具可以提高我们开发界面的效率,下面对几款工具做个对比: 1. Codiqa,在JQuery Mobile主页能看到这款工具,看到网上这么多人吹捧这个工具,不过是收费的. ...

  7. Strider 持续集成(gitlab)

    Strider安装后运行: Mac: strider Ubuntu: bin/strider 本地运行时浏览器访问: http://127.0.0.1:3000 其他服务器:服务器地址 + 端口号(3 ...

  8. 各种边框样式。。本以为border不是这么用的。

    关于文本框样式□ 文本框样式 □ 显示虚线边框的文本框(IE5.5才可看到效果)  <INPUT style="border-width: 1px,1px,1px,1px;border ...

  9. easyui datagrid 部分参数整理

    数据表格属性(DataGrid Properties) 属性继承控制面板,以下是数据表格独有的属性. 名称 类型 描述 默认值 columns array 数据表格列配置对象,查看列属性以获取更多细节 ...

  10. 转】MyEclipse使用总结——修改MyEclipse默认的Servlet和jsp代码模板

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/3769058.html 感谢! 一.修改Servlet的默认模板代码 使用MyEclipse创建Servlet时, ...