hdu 5670 Machine(BC规律题)
2016-04-26 21:54
253 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5670
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 451 Accepted Submission(s): 266
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
BestCoder Round #81 (div.2)
题目大意:有一个机器,它有 m(2≤m≤30)
个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:1. 如果当前状态为红色,它将变成绿色;2.如果当前状态为绿色,它将变成蓝色;3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。初始状态下所有的灯都是红色的。
解题思路:每次都次都是从最右边的彩灯开始变换,那么每按一次最右边就会变,那么从右数第二个每按三个才会变一下,那么右边数第三个呢?就是3的平方=9次,每按9次变换一次,以此类推。。。。
详见代码。
Machine
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 451 Accepted Submission(s): 266
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
BestCoder Round #81 (div.2)
题目大意:有一个机器,它有 m(2≤m≤30)
个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:1. 如果当前状态为红色,它将变成绿色;2.如果当前状态为绿色,它将变成蓝色;3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。初始状态下所有的灯都是红色的。
解题思路:每次都次都是从最右边的彩灯开始变换,那么每按一次最右边就会变,那么从右数第二个每按三个才会变一下,那么右边数第三个呢?就是3的平方=9次,每按9次变换一次,以此类推。。。。
详见代码。
#include <iostream> #include <cstdio> #include <cmath> using namespace std; __int64 ans[110],time[110],s[110]; __int64 Pow(int x,int y) { __int64 ss=1; for (int i=1;i<=y;i++) ss*=x; return ss; } int main() { int t; scanf("%d",&t); while (t--) { __int64 n,m; scanf("%I64d%I64d",&m,&n); int k=0; for (int i=m;i>=1;i--) { s[i]=Pow(3,k); k++; } for (int i=1;i<=m;i++) { time[i]=n/s[i]; ans[i]=time[i]%3; if (ans[i]==0) printf ("R"); else if (ans[i]==1) printf ("G"); else if (ans[i]==2) printf ("B"); } printf ("\n"); } return 0; }
相关文章推荐
- 记录自己的工作点滴
- 一些CSS实现的特效
- leetcode——144——Binary Tree Preorder Traversal
- 问卷信息反馈的反编译
- 镂空点击
- 关于【cocos2d-X】 3.X 安卓如何打包 (我用的3.7.1) 针对第一次打包新手
- 冲刺第九天
- 工具函数(一)
- Generate Parentheses
- Unity之Quaternion学习二
- 教学生jni编程(一)
- 数据挖掘算法-关联规则Apriori
- a3
- 模糊hash算法的一点理解
- code1068 乌龟棋
- Linux进阶之bash编程(流程控制-while,break,continue)
- HTML5视频播放器video和音频播放器audio用法
- html里面Meta标签的使用
- 安卓开发基础
- phpMyAdmin操作之改管理员密码