2012年每周一赛第四场第五题。剪刀石头布的问题,但题目阅读起来相当不解,反复阅读n次之后才明白:这个Sonny本来就想着出RPS,若还要继续就出PSR,若还要继续就出SRP,若还要继续就出回RPS,如此循环下去……问题是如果别人掌握了Sonny的顺序,就能够击败他,所以他就想了个另一个办法去对付这种人(真够无聊的)。首先观察得知,其序列是1-1-1-3-3-9-9-27-27这样的,奥秘就是:对于连续出现的数字,第一个是针对这个数字前面的,而第二个数字就是针对第一个数字的。而你,就是掌握了这个规律的人(道高一尺,魔高一丈啊),在得知要进行多少次的猜拳后,给出最终能够打败Sonny的结果。注意下数据类型的话就没什么问题了。
Run Time: 0sec
Run Memory: 304KB
Code Length: 900Bytes
SubmitTime: 2012-03-17 21:09:11
// Problem#: 4952
// Submission#: 1263779
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <cstdio>
using namespace std;
int root( long long n, int m ) {
int r = 0;
long long temp = 1;
while ( temp < n ) {
temp *= m;
r++;
}
return r - 1;
}
long long pow( int n, int m ) {
long long r = 1;
for ( int i = 1; i <= m; i++ )
r *= n;
return r;
}
int main()
{
long long N;
int bound, count;
while ( scanf( "%lld", &N ) && N ) {
count = 0;
while ( N > 3 ) {
bound = root( N, 3 );
if ( pow( 3, bound ) * 2 < N ) {
N -= pow( 3, bound );
count++;
}
N = N - pow( 3, bound );
count++;
}
count = ( count + N - 1 ) % 3;
if ( count == 0 )
printf( "P\n" );
else if ( count == 1 )
printf( "S\n" );
else
printf( "R\n" );
}
return 0;
}