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";elsereturn "R";}if(n==2){if(step%3==0)return "S";else if(step%3==1)return "R";elsereturn "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;}
}

转载于:https://www.cnblogs.com/qscqesze/p/5135975.html

Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律相关推荐

  1. 【Codeforces 1426 E】Rock, Paper, Scissors,贪心!算反面

    problem E. Rock, Paper, Scissors time limit per test1 second memory limit per test256 megabytes inpu ...

  2. 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FFT)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2021年度训练联盟热身训练赛第四场 H - Rock Paper Scissors(字符串匹配,FF ...

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

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

  4. Python编程基础:第三十七节 石头剪刀布游戏Rock, Paper, Scissors Game

    第三十七节 石头剪刀布游戏Rock, Paper, Scissors Game 前言 实践 前言 我们这一节的内容主要是对前边学习内容的一个综合应用,以石头,剪刀,布游戏为例讲解列表.随机数.用户输入 ...

  5. Codeforces Round #715 (Div. 1) B. Almost Sorted 找规律

    传送门 文章目录 题意: 思路: 题意: 思路: 找规律yydsyydsyyds. 一看没什么想法,所以打了个表,好家伙,不打不知道,一打不得了,下面是n=6n=6n=6的符合要求的情况: 不难发现, ...

  6. CodeForces - 1426E Rock, Paper, Scissors(最小费用最大流+最大费用最大流)

    题目链接:点击查看 题目大意:A 和 B 在玩石头剪刀布,A 会出 a1 次石头,a2 次剪刀,a3 次布,同理 B 会出 b1 次石头,b2 次剪刀,b3 次布,若对战顺序是可以进行决定的,问 A ...

  7. Problem H Rock Paper Scissors,FFT

    题目 题目链接 题意 给出两段石头剪刀布的顺序SSS和T" role="presentation" style="position: relative;&quo ...

  8. 计蒜客A1676 Rock Paper Scissors Lizard Spock

    链接 https://nanti.jisuanke.com/t/A1676 题解 每种分开算,比如我先考虑出 s c i s s o r s scissors scissors,把模式串中的所有 S ...

  9. C - Insertion Sort Gym - 101955C(2018icpc沈阳/打表找规律)

    VJ地址 这道题,首先要把表打出来,表打出来 规律就很容易发现了,一列中它们的差值是等差数列,可以发现公差为2 * dp[j][i], 首项为i * dp[j][i]; 很多人都是直接简化公式,我发现 ...

  10. *【CodeForces - 202C 】Clear Symmetry (思维,找规律,特判)

    题干: Consider some square matrix A with side n consisting of zeros and ones. There are nrows numbered ...

最新文章

  1. Linux Shell学习(3)
  2. LINQ操作数组(交集,并集,差集,最值,平均,去重复)
  3. 用字体选择对话框改变字体
  4. 百度之星 2019 预赛三 A 最短路 1
  5. 反射机制2,Class类的使用
  6. jquery.dataTable.js 绘制表格使用详解
  7. Android USB Host与HID通讯
  8. css --- 使用scss生成常用的基本css样式
  9. matlab im2double
  10. 树链剖分【p3038】[USACO11DEC]牧草种植Grass Planting
  11. 【观察】从实践到赋能再到引领,华为释放数据中心无限潜力
  12. IDEA中自动导包及快捷键
  13. SVN 忽略不需要提交的文件
  14. 要闻君说:华为“发飙”了;快手抛出了1000+社招岗位;迅雷2018年度财报:云连续三年上涨;定论!小米成立AIoT战略委员会...
  15. 简易个人所得税计算器
  16. ASP.NET MVC随想录——锋利的KATANA
  17. unity3D网络游戏实战之坦克单元
  18. kubectl源码分析之rollout history
  19. 学习计算机基本知识,怎样按序学习计算机基本知识
  20. 有哪些回收手机打款快的平台

热门文章

  1. MessageBox--获知点击确认还是取消?
  2. 24bit,192KHz 双通道数模转换电路/立体声数模转换芯片MS4344 可替代CS4344-CZZR
  3. linux驱动学习二---driver
  4. Swift函数式编程十三(函子、适用函子、单子)
  5. Anaconda与ROS共存
  6. 【clickhouse踩坑记录】clusters表中分片副本的浅析
  7. 计算机连接网络被限制,电脑本地连接受限制或无连接怎么办?
  8. 解决Kangle的Easypanel控制面板用户前台php版本无法切换的解决方法
  9. (二)U盘安装Windows Server 2008 R2系统
  10. HijackThis使用详解