Machine

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5670

Description

There is a machine with 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) times?

Input

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

The only line contains two integers m(2≤m≤30) and n(1≤n<263)

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

2

3 1

2 3

Sample Output

RRG

GR

Hint

题意

有一个机器,它有 \(m (2\leq m\leq 30)\) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:

  1. 如果当前状态为红色,它将变成绿色;

2.如果当前状态为绿色,它将变成蓝色;

3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。

初始状态下所有的灯都是红色的。

询问按下按钮 \(n (1\leq n< {2}^{63})\) 次以后各个彩灯的颜色。

题解:

其实就是三进制啦

代码

#include<bits/stdc++.h>
using namespace std;
int a[102];
void solve()
{
int m;long long n;
scanf("%d%lld",&m,&n);
for(int i=0;i<m;i++)
{
a[i]=n%3;
n/=3;
}
for(int i=m-1;i>=0;i--)
if(a[i]==0)printf("R");
else if(a[i]==1)printf("G");
else printf("B");
printf("\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}

HDU 5670 Machine 水题的更多相关文章

  1. hdu 5210 delete 水题

    Delete Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...

  2. hdu 1251 (Trie水题)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  3. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  4. HDU 4493 Tutor 水题的收获。。

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...

  5. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  6. HDU 5670 Machine

    Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  7. hdu 4493 Tutor 水题

    Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...

  8. hdu 5495 LCS 水题

    LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...

  9. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

随机推荐

  1. [004] last_k_node

    [Description] find the k-th node from the last node of single linked list. e.g. Linked-list: 1-2-3-4 ...

  2. Linux内核同步原语之原子操作【转】

    转自:http://blog.csdn.net/npy_lp/article/details/7262388 避免对同一数据的并发访问(通常由中断.对称多处理器.内核抢占等引起)称为同步. ——题记 ...

  3. 有关mysql的innodb_flush_log_at_trx_commit参数【转】

    一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...

  4. c++各种排序的简单实现

    /* 直插排序 */ void InsertSort(vector<int> &arr){ for(int i = 1;i < arr.size();++i){ for(in ...

  5. 在ubuntu上安装Chrome

    1.下载谷歌浏览器源文件.链接有很多,以下是64位版本的下载地址 https://dl.google.com/linux/direct/google-chrome-stable_current_amd ...

  6. 让MySql支持Emoji表情存储

    java后台报错,如下. aused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x84' for column ...

  7. 洛谷 P1184高手之在一起 题解

    题目传送门 那位高手是谁啊?@jxpxcsh  QWQ. 这道题数据特别水,所以直接使用O(n*m),每读进一个m内的字符串,就扫一遍n的字符串.但注意地点字符串中有可能会有空格,所以这时候就要请出g ...

  8. 什么是VC、PE、LP、GP?

    天使基金主要关注原创项目构思和小型初创项目,投资规模大多在300万元以下:风险投资关注初创时期企业长期投资,规模在1000万元以下:私募股权投资主要关注3年内可以上市的成熟型企业. VC即ventur ...

  9. 猜数字游戏的提示(UVa340)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  10. python lxml教程

    目前有很多xml,html文档的parser,如标准库的xml.etree , beautifulsoup  ,  还有lxml. 都用下来感觉lxml不错,速度也还行,就他了. 围绕三个问题: 问题 ...