Machine

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 163    Accepted Submission(s): 99

Problem 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
 
Source
 
题意:有一个机器,它有 m(2≤m≤30)m (2\leq m\leq 30)m(2≤m≤30) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:

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

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

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

初始状态下所有的灯都是红色的。
询问按下按钮 n(1≤n<263)n (1\leq n< {2}^{63})n(1≤n<2​63​​) 次以后各个彩灯的颜色。

 
题解: 可以转换为求 n%(3^m)的三进制数
 
  #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int t;
map<int,char> mp;
ll n;
int m;
int b[];
int main()
{
mp[]='R';
mp[]='G';
mp[]='B';
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %I64d",&m,&n);
int k=;
for(int j=;j<=;j++)
b[j]=;
ll exm=;
for(int i=;i<=m;i++)
exm*=;
if(n>=exm)
n=n%exm;
while(n)
{
b[k]=n%;
n/=;
k++;
}
if(k<m)
{ for(int j=m;j>k;j--)
cout<<"R";
for(int j=k-;j>=;j--)
printf("%c",mp[b[j]]);
}
else
{
for(int j=k-;j>=k-m;j--)
printf("%c",mp[b[j]]);
}
cout<<endl;
}
return ;
}

HDU 5670的更多相关文章

  1. HDU 5670 Machine 水题

    Machine 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5670 Description There is a machine with m(2 ...

  2. HDU 5670 Machine

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

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. P3305 [SDOI2013]费用流

    题目描述 Alice和Bob在图论课程上学习了最大流和最小费用最大流的相关知识. 最大流问题:给定一张有向图表示运输网络,一个源点S和一个汇点T,每条边都有最大流量. 一个合法的网络流方案必须满足: ...

  2. python2.7练习小例子(十八)

    19):题目:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如6=1+2+3.编程找出1000以内的所有完数.      #!/usr/bin/python # -*- ...

  3. RHEL-7.1 Server.x86_64 yum源设置为光盘

    1.挂载光盘 首先在media目录下创建文件夹CentOS mkdir CentOS 然后将光盘挂载在CentOS下 mount -t iso9660 -o loop /dev/cdrom /medi ...

  4. 图表制作工具之ECharts

    简介 ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10 ...

  5. 为WPF中DropShadowBitmapEffect提供轻量级的替代品

    原文:为WPF中DropShadowBitmapEffect提供轻量级的替代品 为WPF中DropShadowBitmapEffect提供轻量级的替代品                         ...

  6. c# string.format和tostring()

    字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0:D3}", ...

  7. C#中利用iTextSharp开发二维码防伪标签(1)

    开发的基本说明与尝试 一个亲戚朋友是做防伪码印刷的,之前的电话防伪.短信防伪都用Delphi给他设计,使用也挺不错,后来又加了一个基于asp的网页版防伪查询.由于业务需求,今年年初朋友又提成希望能够完 ...

  8. cloudera manager服务迁移(scm数据库在postgresql上,其他amon,rman,oozie,metastore等在mysql上)

    公司线上大数据集群,之前用的是公有云主机,现在换成了自己idc机房机器,需要服务迁移,已下为测试: 1.备份原postgresql数据库: pg_dump -U scm scm > scm.sq ...

  9. 实现一个简单版的express

    express应该算是早期最优秀的一个node框架了,刚开始学node做后端语言就是用的express,它的cli可以帮我们搭建好项目目录,就像现在的vue,react一样.express本身没有做太 ...

  10. Sping工作原理

    一. IoC(Inversion of control): 控制反转 1.IoC: 概念:控制权由对象本身转向容器:由容器根据配置文件去创建实例并创建各个实例之间的依赖关系 核心:bean工厂:在Sp ...