hdoj Machine 5670 (模拟)水
来源:互联网 发布:e25歼击车数据 编辑:程序博客网 时间:2024/06/04 17:59
Machine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 683 Accepted Submission(s): 372
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
pushedn(1≤n<263) times?
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
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 integersm(2≤m≤30) and n(1≤n<263) .
The only line contains two integers
Output
For each test case, output the colour of m bulbs from left to right.
R indicates red. G indicates green. B indicates blue.
R indicates red. G indicates green. B indicates blue.
Sample Input
23 12 3
Sample Output
RRGGR
Source
BestCoder Round #81 (div.2)
问题描述
有一个机器,它有 m(2≤m≤30) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:1. 如果当前状态为红色,它将变成绿色;2.如果当前状态为绿色,它将变成蓝色;3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。初始状态下所有的灯都是红色的。询问按下按钮 n(1≤n<263) 次以后各个彩灯的颜色。
输入描述
输入包含多组数据. 第一行有一个整数T(1≤T≤15), 表示测试数据的组数. 对于每组数据:唯一的一行包含2个整数 m(2≤m≤30) 和 n(1≤n<263) 。
输出描述
对于每组数据,输出一个长度为m的字符串,表示从左到右m个彩灯的颜色。R代表红色;G代表绿色;B代表蓝色。
输入样例
23 12 3
输出样例
RRGGR
//思路:
就是一个模拟找规律的题,先将前面的几次的情况模拟出来,很快就会发现规律:
比如m=3,n=8:
RRR 0
RRG 1
RRB 2
RGR 3
RGG 4
RGB 5
RBR 6
RBG 7
RBB 8
从上面的例子就可以推出规律:
最右面的那一位每三次一个循环,往前一位是每9次一个循环(并且连续3个是相同的),再往前一位是每27次一个循环(连续9个是相同的).......
所以根据这个规律就可以做这个题了。
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#define ll long longusing namespace std;ll kp(ll x,ll k){ll s=1;while(k){if(k&1)s*=x;x*=x;k>>=1;}return s;}char judge(int x){if(x==0) return 'R';if(x==1) return 'G';if(x==2) return 'B';}int main(){int t,m;ll n;scanf("%d",&t);while(t--){scanf("%d%lld",&m,&n);for(int i=1;i<=m;i++){ll k=n/kp(3,m-i);k%=3;printf("%c",judge(k));}printf("\n");}return 0;}
0 0
- hdoj Machine 5670 (模拟)水
- HDOJ 5417 Victor and Machine(模拟)
- hdu 5670 Machine(模拟)
- hdoj 5670 Machine 【数学】
- HDOJ 5670 Machine
- hdoj-5670-Machine
- hdu--5670--Machine (模拟三进制)
- hdoj 密码 2043 (模拟水)
- HDOJ 5417 Victor and Machine 水
- HDOJ 1008模拟水题
- HDOJ 5387 Clock 水+模拟
- HDOJ 5038 Grade (模拟)
- hdoj 5912 Fraction(模拟)
- hdu 5417 Victor and Machine(模拟)
- PAT-A1042 Shuffling Machine(简单模拟)
- HDOJ 1150 Machine Schedule
- hdoj 1150 Machine Schedule
- HDOJ 1150 Machine Schedule
- android 解决点击home键,然后点击启动图标重新启动问题
- 微信分享审请AppID、AppSecret注意问题
- 几个网络命令(ping,telnet,ssh,netstat)
- [论文阅读]HyperNet: Towards Accurate Region Proposal Generation and Joint Object Detection
- Sublime Text 3 使用技巧
- hdoj Machine 5670 (模拟)水
- 栈template
- 解决 PermGen space Tomcat内存设置
- src与href属性的区别
- MySQL添加外键失败ERROR 1452的解决
- 树——从最下层向上打印二叉树(层序遍历扩展)
- textarea根据内容自动增长
- Centos 7.2 JDK8 安装
- 使用UIScrollViewKeyboardDismissMode实现了Message app的行为