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. html 弹框 优化 alert

    <!DOCTYPE html> <html> <head> <title>cs</title> </head> <styl ...

  2. Java学习笔记四:Java的八种基本数据类型

    Java的八种基本数据类型 Java语言提供了八种基本类型.六种数字类型(四个整数型,两个浮点型),一种字符类型,还有一种布尔型. Java基本类型共有八种,基本类型可以分为三类,字符类型char,布 ...

  3. c#vs连接SQL sever数据库入门操作

    对于需要连接数据库的项目,可以参考的简单初级代码.实现打开数据库,读入数据功能 using System; using System.Collections.Generic; using System ...

  4. Xshell启动时显示丢失MSVCP110.dll解决方法

    成功安装xshell之后,在运行时却弹出“无法启动此程序,因为计算机中丢失MSVCP110.dll.尝试重新安装该程序以解决此问题”,很多人按照提示重装了还是出现同样的问题,本集教程将具体讲解如何处理 ...

  5. 导入execl到数据库mysql

    GwykhrenyuankuList <body jwcid="$content$"> <span jwcid="@components/AppBord ...

  6. 9.0 toast定位+WebDriverWait显示等待

    Toast  判断-----基本操作问题 首先基本操作,进入安卓市场的账号密码页面--- from appium import webdriver from selenium.webdriver.su ...

  7. Spark概念介绍

    Spark概念介绍:spark应用程序在集群中以一系列独立的线程运行,通过驱动器程序(Driver Program)发起一系列的并行操作.SparkContext对象作为中间的连接对象,通过Spark ...

  8. Drools 7.4.1.Final参考手册(六) 用户手册

    用户手册 基础 无状态的知识Session Drools规则引擎拥有大量的用例和功能,我们要如何开始?你无须担心,这些复杂性是分层的,你可以用简单的用例来逐步入门. 无状态Session,无须使用推理 ...

  9. DFS(3)——poj1321棋盘问题

    一.题目回顾 题目链接:棋盘问题 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于 ...

  10. 日历插件DatePicker

    Datepicker 地址:https://getuikit.com/v2/docs/datepicker.html