Machine
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 290 Accepted Submission (s): 179
problem DescriptionThere is a machine withm(2≤m≤) Coloured bulbs and a button. When the button is pushed, the rightmost bulb changes.
For any changed bulb,
If it is red now it'll be green;
If it is green now it would be blue;
If it is a blue now it would be the red and the bulb, the left (if it exists) would change too.
Initally all the bulbs is red. What colour is the bulbs after the button is
Pushed N(1≤n<2^) times?
InputThere is multiple test cases. The first line of input contains an integerT(1≤t≤) indicating the number of test cases. For each test case:
The only line contains and integersm(2≤m≤) and N(1≤n<2) .
OutputFor each test case, the output of the colour of m bulbs from left to right.
R indicates red. G indicates green. B indicates blue.
Sample Input23 12 3
Sample OutputRRGGR
recommendwange2014
The main idea: all the lights in the initial state are red, and the output is changed by N times.
idea: is to convert this number to 3, 0,1,2, respectively, red, green, blue ...
#include <iostream>#include<cstdio>using namespacestd;intMain () {intj=0, I, T, M, a[ $];__int64 n;cin>>T; while(t--) {J=0; scanf ("%d%i64d", &m, &n); while(n!=0) {a[++j]=n%3; N=n/3;} while(m>j) {cout<<"R"; M--;} for(i=m;i>=1; i--)if(a[i]==0) printf ("R");Else if(a[i]==1) printf ("G");Elseprintf ("B");p rintf ("\ n");} return 0;}
HDU 5670 Machine