hdu 5670 Machine(BC规律题)

题目链接: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次变换一次,以此类推。。。。

详见代码。

<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;
}
				
时间: 2024-10-09 04:34:48

hdu 5670 Machine(BC规律题)的相关文章

HDU 4937 Lucky Number 规律题_(:зゝ∠)_

把所有合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> typedef long long ll; bool ok(ll x, ll y) { ll v; while (x > 0) { v = x % y; if (v != 3 && v != 4 && v != 5 && v != 6) return false;

HDU 4952 Number Transformation 规律题

打表可以知道到后面增量都一样了,, 推论就是  i 和 i+1 互质 #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const ll mx = 120000; int main() { int cas = 0; ll x, k, y, dis, i; while (

HDU 5670 Machine

Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 290    Accepted Submission(s): 179 Problem Description There is a machine with m(2≤m≤30) coloured bulbs and a button.When the button is pu

HDU 5422-Rikka with Graph(规律题)

题目地址:HDU 5422 题意: 思路: 如果连上1-n的边,最短距离就是1.所以所有情况下最短距离都是1.考虑方案数,如果本来没有1-n的边,那么只能连1-n,方案数为1.否则怎么连都可以,方案数是n*(n-1)/2. int main() { int n,m; int x,y; while(~scanf("%d %d",&n,&m)) { int flag = 0; for(int i=0; i<m; i++) { scanf("%d %d&quo

hdu 5671 Matrix(BC——思维题)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=5671 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 891    Accepted Submission(s): 371 Problem Description There is a matrix M that has n rows

HDU 4357 String change 规律题

题意: 给定a串b串,问能否把a变成b串 方法:任选a的2个字母,ascil+=1 然后交换位置,可以操作任意多次. 3个及3个以上一定可以T^T 2个就暴力判一下 #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 66; char a[N], b[N]; bool check() {

HDU 4279 Number 规律题

题意: 定义函数F(x) : 区间[1,x]上的y是满足:GCD(x,y)>1 && x%y>0的 y的个数. 问:对于任意区间[l,r] 上的F(l···r) 有几个函数值是奇数的. 打表找规律. 打的是[1,x]区间的结果 把所有结果不相同的值打出来(因为结果是递增的,所以只观察不相同的结果) 发现:ans = x/2-2 || x/2-1 再把所有结果不同 && x/2-1的值打出来 发现 sqrt(x) &1 == 1 得到:ans = x/2-

HDU 4940 Destroy Transportation system 规律题

答案只有2种情况,所以ans = rand()%2; if(ans)puts("happy") else puts("unhappy"); == 想过无源汇的网络流,还是比较麻烦的,然后没往下想... 设s点集有一些点, 多加一个点一定是y增加比较快_(:зゝ∠)_ 然后设s点集只有一个点 #include <cstdio> #include <map> #include <set> #include <algorithm&

HDU 4148 Length of S(n)(规律题)

Problem Description http://acm.hdu.edu.cn/showproblem.php?pid=4148 A number sequence is defined as following: S(1)=1, S(2)=11, S(3)=21, S(4)=1211, S(5)=111221, S(6)=312211, -- Now, we need you to calculate the length of S(n). Input The input consists