Bestcoder Round #81 (Div.2) 1001

Source: Internet
Author: User

Machineaccepts:580submissions:1890Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others)Problem Description

There is a machine with m (2≤m≤30) m (2\leq M\leq)m(2≤m≤30) 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<263) n (1\leq n< {2}^{63})n(1≤ n <2? 63?? ) times?

Input

There is multiple test cases. The first line of input contains an integer t (1≤t≤15) T (1\leq T\leq)T(1≤t≤1 5 ) indicating the number of test cases. for each test case:

The only line contains and integersM (2≤m≤30) m (2\leq M\leq 30)M(2≤M≤30) and n (1≤n<263) n (1\leq n< {2}^{63}) n (1≤n<2? 6 3??

Output

For 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 InputCopy
23 12 3
Sample OutputCopy
Rrggr
Main topic:
is a row of bulbs, the initial time each bulb color is red, at the same time there is a button, each point once, will be the right side of the light bulb color will change,
The rule of change is r->g->b->r, cycle by loop, but when the bulb is from b->r, the color of the bulb on its left will change accordingly.
Thinking Analysis: Long time did not knock code, rusty not, was so a water problem pit for half a day, the first is the input time, n range is very large, should be with LLD or i64d
Input, the other n value is so big, I unexpectedly first thought is simulates again, Orz, time out, each bulb's final color is only related to the remainder of n%3, so the judgment is undoubtedly
The most time-saving.
Code:
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace Std;
const int maxn=35;
Char BULB[MAXN];
int main ()
{
int T;
scanf ("%d", &t);
while (t--)
{
__int64 M,n;
scanf ("%i64d%i64d", &m,&n);
memset (Bulb, ' R ', sizeof (bulb));
for (int i=0;i<m;i++)
{
if (n==0) break;
if (n%3==0) bulb[i]= ' R ';
if (n%3==1) bulb[i]= ' G ';
if (n%3==2) bulb[i]= ' B ';
n/=3;
}
for (int i=m-1;i>=0;i--)
printf ("%c", Bulb[i]);
printf ("\ n");
}
return 0;
}

Bestcoder Round #81 (Div.2) 1001

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.