HDU-5670 Machine
题目:
Machine Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 543 Accepted Submission(s): 313
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
代码:
1 | // oj.cpp : 定义控制台应用程序的入口点。 |
解析&吐槽:
一道水题。注意最右边的灯泡是按一下按钮改变一次,从右边数第二个灯泡是按 3 下按钮改变一次,第三个是 9 下按钮。因此第 n 个就是按 3^(n-1)个按钮改变一次了。 本题的幂运算需要自己写函数,cmath 自带的 pow 没法返回 long long,会因精度损失而导致 wa。
本作品采用 署名-相同方式共享 4.0 国际 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名 “不科学的科学君” (Liu233w) 与博客链接: https://liu233w.github.io ,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系 。