原题:
A Another Rock-Paper-Scissors Problem

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:

R P S PSR SRP PSRSRPRPS SRPRPSPSR PSRSRPRPSSRPRPSPSRRPSPSRSRP …

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?

A.1 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.

A.2 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

题目大意:
小明的猜拳策略,先出R,然后每连续两段出拳策略是前一阶段的获胜方法。
样例:
R P S PSR SRP PSRSRPRPS SRPRPSPSR PSRSRPRPSSRPRPSPSRRPSPSRSRP….
第二个P可以赢第一个R,第三个S可以赢第二个P。接着的PSR可以赢前一阶段的RPS,SRP可以赢PSR。然后PSRSRPRPS可以赢R P S PSR SRP,SRPRPSPSR可以赢PSRSRPRPS。以此类推。
求给定轮数胜利的策略。

分析:
通过观察可以发现,这个出拳策略和3有关(显然)。我们可以由3的次方数来分组,递归查找,出拳顺序的变换一定是S->P->R(每一次都要赢前一次的对应位置)。所以如果n是某个3的次方数的(1,2】倍之间,就需要往前推一个拳,如果是(2,3】之间,就需要往前推两个,然后去求n mod这个3的次方数的轮数即可。

ac代码:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int solve(int cnt);
ll ow(int n,int m);
char res[][4]={"PSR","SRP","RPS"};
ll num;
int main()
{while(~scanf("%I64d",&num)&&num){int ans;ans=solve(0);ans=ans%3;printf("%c\n",res[num-1][ans]);}
}
int solve(int cnt)
{if(num>=1&&num<=3)return cnt;int i=1;for(i=1;;i++){if(ow(3,i)>=num)break;}if(num>ow(3,i-1)&&num<=2*ow(3,i-1)){num-=ow(3,i-1);solve(cnt+1);}else if(num>2*ow(3,i-1)&&num<=3*ow(3,i-1)){num-=2*ow(3,i-1);solve(cnt+2);}}
ll ow(int n,int m)
{ll res=1;for(int i=1;i<=m;i++)res=res*n;return res;
}

简化版(转):

#include<stdio.h>
long long n,t[26]={1};
char s[4]="RPS";
int main(){for(int i=1;i<=25;i++)t[i]=t[i-1]*3;while(scanf("%I64d",&n)&&n){int i=25,a=0;while(n>3){while(n<=t[i])i--;while(n>t[i]){n-=t[i];a++;//推的次数}}printf("%c\n",s[(n+a)%3]);//n为1 2 3,对应PSR//a为推的次数//(n+a)mod 3为对应的拳// 0对应R,1对应P,2对应S}return 0;
}

博客第一题。

Gym 100015A相关推荐

  1. 强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例

    强化学习(三) - Gym库介绍和使用,Markov决策程序实例,动态规划决策实例 1. 引言 在这个部分补充之前马尔科夫决策和动态规划部分的代码.在以后的内容我会把相关代码都附到相关内容的后面.本部 ...

  2. Gym - 102082G

    Gym - 102082G https://vjudge.net/problem/2198225/origin 对于数列中任意一个数,要么从最左边到它不递减,要么从最右边到到它不递减,为了满足这个条件 ...

  3. 安装gym库_强化学习Gym库学习实践(一)

    最近看了一篇研究方向相关的文章,介绍了一种DQN的应用,感觉还挺新鲜的.想着把这篇文章复现出来,就开始学习强化学习的相关知识,作为一名小白,这一路走的可是真的十分艰难(我太菜了啊!) 看了莫烦Pyth ...

  4. 强化学习环境库 Gym 发布首个社区发布版,全面兼容 Python 3.9

    作者:肖智清 来源:AI科技大本营 强化学习环境库Gym于2021年8月中旬迎来了首个社区志愿者维护的发布版Gym 0.19.该版本全面兼容Python 3.9,增加了多个新特性. 强化学习环境库的事 ...

  5. Gym迎来首个完整环境文档,强化学习入门更加简单!

    深度强化学习实验室 官网:http://www.neurondance.com/ 论坛:http://deeprl.neurondance.com/ 编辑:OpenDeepRL OpenAI Gym是 ...

  6. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  7. Ubuntu下常用强化学习实验环境搭建(MuJoCo, OpenAI Gym, rllab, DeepMind Lab, TORCS, PySC2)

    原文地址:http://blog.csdn.net/jinzhuojun/article/details/77144590 和其它的机器学习方向一样,强化学习(Reinforcement Learni ...

  8. OpenAI Gym介绍

    上篇博客介绍了OpenAI Gym.OpenAI Gym与强化学习以及OpenAI Gym的安装,接下来运行一个demo体验一下OpenAI Gym这个平台,以CartPole(倒立摆)为例,在工作目 ...

  9. 独家 | 使用Python的OpenAI Gym对Deep Q-Learning的实操介绍(附学习资源)

    作者:ANKIT CHOUDHARY 翻译:张睿毅 校对:吴金笛 本文4300字,建议阅读10+分钟. 本文作者通过实战介绍了Deep Q-Learning的概念. 导言 我一直对游戏着迷.在紧凑的时 ...

  10. 强化学习gym库中的Pendulum-v1/CartPole-v1游戏介绍

    文章目录 前言 CartPole-v1 游戏结束 state action和reward Pendulum-v1 通用操作 前言 gym官网:http://gym.openai.com/envs/#c ...

最新文章

  1. navicat for mysql 显示中文乱码解决办法
  2. Linux网络基本配置
  3. iHealth基于Docker的DevOps CI/CD实践
  4. mysql left join第一个_MySQL 之 LEFT JOIN 避坑指南
  5. 国际码可以直接应用于计算机,2012年自考计算机应用基础试题及答案
  6. JAVA转smali软件_Java2Smali(Java代码转Smali工具)
  7. thinkphp 表单令牌
  8. 分布式唯一id生成器的想法
  9. linux下批量查找UTF-8的BOM文件,并去除BOM
  10. Unity3d C#使用Highlighting System 5.0高光插件的详细使用教学和脚本动态操作
  11. linux 分区100g整数,[转载]硬盘分区 整G 整数 法(从1g到200g最精确的整数分区)(转)...
  12. 液压系统仿真软件_利用仿真软件判断系统稳定
  13. Java开发快递物流项目(1)
  14. Facebook攻略--运营方式
  15. 多种多样的语音连麦方式
  16. win10命令提示符怎么打开_win10死机出现蓝屏代码SYSTEM_PTE_MISUSE怎么解决
  17. mysql左链sql去重_MySql去重
  18. android 陀螺仪加速度传感器,如何在Android智能手机中使用加速度传感器...
  19. Xcode 和 Mac 的一些快捷键
  20. realme支持鸿蒙系统,骁龙888+首批搭载安卓12,realme真我GT真香售价2499元起

热门文章

  1. 面试热问——你的职业规划是什么?
  2. html 中数字一直往上加的动态效果,CSS动画:数字增量效果
  3. 论html5十大优点
  4. vue上传图片限制格式以及尺寸大小
  5. sklearn中KMeans重要参数n_clusters
  6. 浏览器的窗口大小被改变时触发的事件window.onresize
  7. 利用支付宝短信服务接口 实现手机号 验证码登录Demo
  8. tf.sigmoid
  9. 【综述】(MIT博士)林达华老师-quot;概率模型与计算机视觉”
  10. Linux中对的tac命令