HDU 5670 Machine 水题
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)\) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:
- 如果当前状态为红色,它将变成绿色;
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 水题的更多相关文章
- hdu 5210 delete 水题
Delete Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5210 D ...
- hdu 1251 (Trie水题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- HDU 4493 Tutor 水题的收获。。
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意我都不好意思说,就是求12个数的平均数... 但是之所以发博客,显然有值得发的... 这个题最 ...
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- HDU 5670 Machine
Machine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu 4493 Tutor 水题
Tutor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 D ...
- hdu 5495 LCS 水题
LCS Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5495 Descr ...
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
随机推荐
- 【C++自我精讲】基础系列六 PIMPL模式
[C++自我精讲]基础系列六 PIMPL模式 0 前言 很实用的一种基础模式. 1 PIMPL解释 PIMPL(Private Implementation 或 Pointer to Implemen ...
- Java Spring boot 企业微信点餐系统
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- Ubuntu之镜像iso安装系统
ubuntu的安装 官网下载iso文件,网址:http://releases.ubuntu.com/16.04.4/, 选择:ubuntu-16.04.4-server-amd64.iso: 下载完毕 ...
- SurfaceFlinger 讲解
SurfaceFlinger是Android multimedia的一个部分,在Android 的实现中它是一个service,提供系统 范围内的surface composer功能,它能够将各种应用 ...
- angular项目中使用angular-material2
Step 1: Install Angular Material and Angular CDK npm install --save @angular/material @angular/cdk n ...
- DBCP object created 日期 by the following code was never closed:
1.分析 看到标题 DBCP 首先想到的肯定是 数据库连接池哪方面有问题,那么先别着急去解决,不要一股脑就钻进逻辑代码中,然后启用调试就开始一步一步 的分析.我们首先要做的就是想,想想数据库连接池,在 ...
- Linux内核的三种调度策略
一 Linux内核的三种调度策略: 1,SCHED_OTHER 分时调度策略, 2,SCHED_FIFO实时调度策略,先到先服务.一旦占用cpu则一直运行.一直运行直到有更高优先级任务到达或自己放 ...
- POJ 1386 Play on Words(单词建图+欧拉通(回)路路判断)
题目链接:http://poj.org/problem?id=1386 题目大意:给你若干个字符串,一个单词的尾部和一个单词的头部相同那么这两个单词就可以相连,判断给出的n个单词是否能够一个接着一个全 ...
- spring mvc整合mybaitis和log4j
在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...
- Reflow(回流)和Repaint(重绘) (转)
原文地址:http://blog.csdn.net/qq_18826911/article/details/68924255 首先我们要明白的是,页面的显示过程分为以下几个阶段: 1.生成DOM树(包 ...