码迷,mamicode.com
首页 > 系统相关 > 详细

hdu 5670 Machine(BC规律题)

时间:2016-04-29 17:07:47      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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(2m30) 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(1n<263) times?
 

Input
There are multiple test cases. The first line of input contains an integer T(1T15) indicating the number of test cases. For each test case:

The only line contains two integers m(2m30) and n(1n<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

题目大意:有一个机器,它有 m(2m30) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:1. 如果当前状态为红色,它将变成绿色;2.如果当前状态为绿色,它将变成蓝色;3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。初始状态下所有的灯都是红色的。
解题思路:每次都次都是从最右边的彩灯开始变换,那么每按一次最右边就会变,那么从右数第二个每按三个才会变一下,那么右边数第三个呢?就是3的平方=9次,每按9次变换一次,以此类推。。。。
详见代码。
<pre name="code" class="cpp">#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;
}



hdu 5670 Machine(BC规律题)

标签:

原文地址:http://blog.csdn.net/qiqi_skystar/article/details/51254555

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!