【BestCoder Round #81 (div.2)】HDU5670Machine

来源:互联网 发布:最好的建筑设计软件 编辑:程序博客网 时间:2024/04/30 01:19

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5670

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

代码:

#include<iostream>using namespace std;int main(){    int t;    long long m,n;    long long a[30];    a[1]=3;a[0]=1;    for(int i=1;i<30;i++){        a[i]=3*a[i-1];    }    cin>>t;    while(t--){        cin>>m>>n;        for(int i=m;i>=1;i--){            switch((n/a[i-1])%3){                case 0:                    cout<<'R';                    break;                case 1:                    cout<<'G';                    break;                case 2:                    cout<<'B';                    break;            }        }        cout<<endl;    }    return 0;}


0 0
原创粉丝点击