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. ZOJ3558 How Many Sets III(公式题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud How Many Sets III Time Limit: 2 Seconds   ...

  2. CentOS 5.5安装图解教程

    说明:实际生产环境中,CentOS 5.5这个版本相当稳定,而且硬件兼容性也很好,是很多服务器装机者的首选系统,下面介绍CentOS 5.5的具体安装过程   说明:实际生产环境中,CentOS 5. ...

  3. Backbone一些参考资源

    最近想找一个single-page JavaScript application Framework ,而不是单纯的Toolkit+Widget.来看YUI3的一段介绍: 引用 The YUI App ...

  4. [转]MVC模式已死?何不试试MOVE

    在36Kr看到一篇译文,主要是提出一些新的概念,升华老的MVC模式.看上很不错,转过来,做个记录. ========================= 华丽的分割线 ================= ...

  5. C语言在单片机开发中的应用

    在单片机的开发应用中,已逐渐开始引入高级语言,C语言就是其中的一种.对用惯了汇编的人来说,总觉得高级语言’可控性’不好,不如汇编那样随心所欲.但是只要我们掌握了一定的C语言知识,有些东西还是容易做出来 ...

  6. WCF基于Cookie回传的系列(概述)

    1  WCF的基本知识(不作细述,园子里有很多的经典的文章系列) 2 WCF的执行过程 3 让服务通信像浏览器发送请求应答一样回传Cookie,并实现Cookie在不同的服务间共享 4  基于共享后的 ...

  7. vs2010 suite integration toolkit execution

    原因是UltraDeamen的问题,重新换个WinMount来解压ISO文件.完美安装运行

  8. JPA中以HibernatePersistence为provider的批量插入问题

    为什么要批量插入 要插入10000条数据,如果不批量插入的话,那么我们执行的sql语句将是10000条insert insert into member (group_id, user_id, rol ...

  9. 【Android】通过Java代码替换TabHost中的drawableTop资源

    在博客 http://blog.csdn.net/jueblog/article/details/11837445 中的Tab选项卡中, 点击相应的Tab选项,图标没有发生改变. 这些资源图片也没有尽 ...

  10. cf445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...