您的位置:首页 > 其它

hdu 5670 Machine(BC规律题)

2016-04-26 21:54 253 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5670


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;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: