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. 码云配置webhooks自动触发拉取代码

    webhooks的使用 码云和github的钩子叫webhooks 每次您 push 代码后,都会给远程 HTTP URL 发送一个 POST 请求 码云项目管理页面的webhooks设置: http ...

  2. flask迁移

    from flask_script import Managerfrom flask_migrate import Migrate, MigrateCommandfrom info import cr ...

  3. 004---Linux系统设置

    Linux版本相关命令 查看系统版本:cat /etc/redhat-release 查看系统内核版本以及位数:uname -r [root@hostname1 ~]# cat /etc/redhat ...

  4. JAVA 反射之Method

    ★ Method没有构造器,只能通过Class获取. 重点方法: class.getDeclaredMethods():获取所有方法. class.getDeclaredMethod(String n ...

  5. ListView学习

    ListView类 常用的基本属性 FullRowSelect:设置是否行选择模式.(默认为false)提示:只有在Details视图,该属性有效. GridLines:设置行和列之间是否显示网格线. ...

  6. 【转】Linux系统安装Redis详细过程

    本文来源 https://blog.csdn.net/qq_20989105/article/details/76390367 ,转载前请先联系原作者并声明出处. 一.安装gcc 1.Redis在li ...

  7. java图片识别 [Tesseract-OCR]

    以下链接包含,安装包及程序运行需要的jar 包,中文资源包. 中文包使用方式:找到tessdata安装目录(我本地:C:\Program Files (x86)\Tesseract-OCR\tessd ...

  8. 为什么我要放弃javaScript数据结构与算法(第三章)—— 栈

    有两种结构类似于数组,但在添加和删除元素时更加可控,它们就是栈和队列. 第三章 栈 栈数据结构 栈是一种遵循后进先出(LIFO)原则的有序集合.新添加的或待删除的元素都保存在栈的同一端,称为栈顶,另一 ...

  9. CentOS搭建Sqoop环境

              Sqoop是一个用来将Hadoop(Hive.HBase)和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如:MySQL ,Oracle ,Postgres等)中的 ...

  10. MVC使用ajax取得JSon数据

    为了在view中获取模型中的数据,用ajax异步模式读取数据,再用json返回的view中. 1.controller中: [HttpPost] public ActionResult GetAjax ...