hdoj 【BestCoder Round #81 (div.2)】 5670 Machine

来源:互联网 发布:创业项目 知乎 编辑:程序博客网 时间:2024/06/05 00:37


Problem Description
There is a machine with m(2m30) coloured bulbs and a button.When the button is pushed, the rightmost bulb changes.
For any changed bulb,

if it is red now it will be green;

if it is green now it will be blue;

if it is blue now it will be red and the bulb that on the left(if it exists) will change too. 

Initally all the bulbs are red. What colour are the bulbs after the button be 
pushed n(1n<263) times?
 

Input
There are multiple test cases. The first line of input contains an integer T(1T15) indicating the number of test cases. For each test case:

The only line contains two integers m(2m30) and n(1n<263).
 

Output
For each test case, output the colour of m bulbs from left to right.
R indicates red. G indicates green. B indicates blue.
 

Sample Input
23 12 3
 

Sample Output
RRGGR
 
     给出一排彩色的灯,并且他们都连在同一个开关上。这些彩灯有R红,G绿,B蓝三种颜色,当按下开关时,最右边若是红灯,则变为绿灯,如果是绿灯则变为蓝灯,如果是蓝灯将再次变为红灯且它左边相邻的灯也会按照此顺序发生改变。即右边的灯变三次,左边的灯变一次.
代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char str[33];char st[3]={'R','G','B'};int main(){int t ;scanf("%d",&t);while(t--){int m;__int64 n;int i;scanf("%d%I64d",&m,&n);for(i=0;i<33;i++)str[i]='R';    for(i=m-1;i>=0;i--)    {    str[i]=st[n%3];    n/=3;}for(i=0;i<m;i++){printf("%c",str[i]);}printf("\n");}}


Problem Description
There is a machine with m(2m30) coloured bulbs and a button.When the button is pushed, the rightmost bulb changes.
For any changed bulb,

if it is red now it will be green;

if it is green now it will be blue;

if it is blue now it will be red and the bulb that on the left(if it exists) will change too. 

Initally all the bulbs are red. What colour are the bulbs after the button be 
pushed n(1n<263) times?
 

Input
There are multiple test cases. The first line of input contains an integer T(1T15) indicating the number of test cases. For each test case:

The only line contains two integers m(2m30) and n(1n<263).
 

Output
For each test case, output the colour of m bulbs from left to right.
R indicates red. G indicates green. B indicates blue.
 

Sample Input
23 12 3
 

Sample Output
RRGGR
 

0 0