HDU 5670 Machine

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.