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. linux上 安装并 运行opencv

    我是在树莓派上安装的. 1.先安装依赖项 OpenCV 2.2以后版本需要使用Cmake生成makefile文件,因此需要先安装cmake. sudo apt-get install build-es ...

  2. java学习笔记 (2) —— Struts2类型转换、数据验证重要知识点

    1.*Action.conversion-properties 如(point=com.test.Converter.PointListConverter) 具体操作类的配置文件 2.*Action. ...

  3. php中计算中文字符串长度、截取中文字符串

    在做PHP开发的时候,由于我国的语言环境问题,所以我们常常需要对中文进行处理.在PHP中,我们都知道有专门的mb_substr和mb_strlen函数,可以对中文进行截取和计算长度,但是,由于这些函数 ...

  4. 使用laravel的任务调度(定时执行任务)

    laravel中有一个很强大上的功能,只需要在服务器上添加一个cron条目,就可以定时执行所有的laravel任务. 现在有如下数据表: 我想让cron表中的cron字段的值每分钟增加1,那么我需要如 ...

  5. Xcode6中自动布局autolayout和sizeclass的使用

    Xcode6中自动布局autolayout和sizeclass的使用   一.关于自动布局(Autolayout) 在Xcode中,自动布局看似是一个很复杂的系统,在真正使用它之前,我也是这么认为的, ...

  6. 开源 一行代码实现多形式多动画的推送小红点WZLBadge(iOS)-备用

    更新日志 V1.2 2015.09.25 1.UITabBarItem badge is supproted; 2.Enable change badge properties when badge ...

  7. Effective Java Item2:Consider a builder when faced with many constructor parameters

    Item2:Consider a builder when faced with many constructor parameters 当构造方法有多个参数时,可以考虑使用builder方式进行处理 ...

  8. Codeforces 538E Demiurges Play Again(博弈DP)

    http://codeforces.com/problemset/problem/538/E 题目大意: 给出一棵树,叶子节点上都有一个值,从1-m.有两个人交替从根选择道路,先手希望到达的叶子节点尽 ...

  9. 面试题 46 1+ 2+3+...+n

    class Temp{ public: Temp(){ ++N; sum+=N; } static void Reset(){ N = ; sum = ; } static int getSum(){ ...

  10. 购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(3)--Idetity,OWIN前后端验证

    原文:购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(3)--Idetity,OWIN前后端验证 chsakell分享了前端使用AngularJS,后端使用ASP. ...