Machine

Accepts: 580
Submissions: 1890
Time 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 30)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 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(1≤n<263)n (1\leq n< {2}^{63})n(1≤n<2​63​​) times?

Input

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

The only line contains two integers m(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​63​​).

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
Copy

2
3 1
2 3
Sample Output
Copy

RRG
GR
题目大意:
就是有一排灯泡,初始时每一个灯泡的颜色都是红色,同时有一个Button,每点一次,就会时最右边的灯泡的颜色都会发生变化,
变化规则为R->G->B->R,周而复始进行循环,但是当灯泡是从B->R时,它左边的灯泡的颜色也会相应的发生变化。
思路分析:好久没敲代码了,手生的不行,被这么一道水题坑了半天,首先是输入的时候,n的范围很大,应该用lld或者I64d进行
输入,另外n值这么大,我竟然第一想法是模拟一遍,orz,超时了,每一个灯泡的最终颜色只与n%3的余数有关,这样进行判断无疑是
最省时间的。
代码:
#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的更多相关文章

  1. BestCoder Round #81 (div.2) 1004 String(动态规划)

    题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...

  2. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

  3. BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)

    题目:Click here 题意:bestcoder上面有中文题目 #include <iostream> #include <cstdio> #include <cst ...

  4. BestCoder Round #81 (div.2) 1003 String

    题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...

  5. BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...

  6. BestCoder Round #81 (div.2)C String

    总体思路好想,就是在找K个不同字母的时候,卡时间. 看了大神代码,发现goto的!!!!998ms #include<cstdio> #include<cstring> #in ...

  7. BestCoder Round #81 (div.2) B Matrix

    B题...水题,记录当前行是由原矩阵哪行变来的. #include<cstdio> #include<cstring> #include<cstdlib> #inc ...

  8. BestCoder Round #81 (div.1)A

    水题...就是n的三进制后m位 #include<cstdio> #include<cstring> #include<cstdlib> #include<i ...

  9. BestCoder Round #81 (div.2)

    HDU:5670~5764 A题: 是一个3进制计数: #include <bits/stdc++.h> using namespace std; ]; int calc(long lon ...

随机推荐

  1. jQuery select 操作全集

    添加option $('#id').append("<option value="value">Text</option>");//为s ...

  2. django settings最佳配置

    # encoding=utf-8 import os import socket SITE_ID = 1 # 项目的根目录 # 简化后面的操作 PROJECT_ROOT = os.path.dirna ...

  3. About abstract class.

    Abstract means should be realized. Virtual means could be overrided. It is very different!

  4. iOS学习之网易新闻简易Demo

    简易NewsDemo代码分析 界面布局就不多说了.效果图:(自定义了三套Cell,最后一套Cell是页面最下方的"正在加载中..."Cell,图三.)         主要分析工程 ...

  5. GO语言可以直接输出数组

    package main import "fmt" func main(){ ]int ;i<;i++{ arr[i]=i } fmt.Printf("%v&quo ...

  6. js深入研究之自定义混合Mixin函数

    <script type="text/javascript"> /* 增加函数 */ function augment(receivingClass, givingCl ...

  7. cf492A Vanya and Cubes

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. CSDN第四届在线编程大赛2014初赛:带通配符的数

    题目要求: 输入参数:参数A,含有任意个数的?的数值字符串,如:12?4,?代表一位任意数             参数B,不含?的数值字符串,长度与参数A一致输出结果:参数A比参数B大的可能数值个数 ...

  9. STL中,back_insert_iterator与back_inserter的区别。

    1.参考http://www.cplusplus.com网站关于back_insert_iterator与back_inserter的介绍之后,我总算明白了:back_insert_iterator, ...

  10. Python Scrapy安装杂症记录

    昨天安装了scrapy一切正常,调试了bbsSpider案例(详见上文),今日开机因为冰封还原,提示找不到python27.dll,重新安装了python2.7, 使用easy-install scr ...