zoukankan      html  css  js  c++  java
  • HDU 5670

    Machine

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 163    Accepted Submission(s): 99


    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(2≤m≤30)m (2leq mleq 30)m(2m30) 个彩灯和一个按钮。每按下按钮时,最右边的彩灯会发生一次变换。变换为:

    1. 如果当前状态为红色,它将变成绿色;

    2.如果当前状态为绿色,它将变成蓝色;

    3.如果当前状态为蓝色,它将变成红色,并且它左边的彩灯(如果存在)也会发生一次变换。

    初始状态下所有的灯都是红色的。
    询问按下按钮 n(1≤n<263)n (1leq n< {2}^{63})n(1n<263​​) 次以后各个彩灯的颜色。
     
    题解: 可以转换为求 n%(3^m)的三进制数
     
     1  #include<iostream>
     2  #include<cstring>
     3  #include<cstdio>
     4  #include<queue>
     5  #include<stack>
     6  #include<map>
     7  #include<set>
     8  #include<algorithm>
     9  #define ll __int64
    10  #define pi acos(-1.0)
    11  #define mod 1
    12  #define maxn 10000
    13  using namespace std;
    14  int t;
    15  map<int,char> mp;
    16  ll n;
    17  int m;
    18  int b[35];
    19  int main()
    20  {
    21      mp[0]='R';
    22      mp[1]='G';
    23      mp[2]='B';
    24      scanf("%d",&t);
    25      for(int i=1;i<=t;i++)
    26      {
    27          scanf("%d %I64d",&m,&n);
    28          int k=0;
    29          for(int j=0;j<=31;j++)
    30           b[j]=0;
    31          ll exm=1;
    32           for(int i=1;i<=m;i++)
    33              exm*=3;
    34         if(n>=exm)
    35             n=n%exm;
    36          while(n)
    37          {
    38              b[k]=n%3;
    39              n/=3;
    40              k++;
    41         }
    42         if(k<m)
    43         {
    44           
    45             for(int j=m;j>k;j--)
    46              cout<<"R";
    47              for(int j=k-1;j>=0;j--)
    48              printf("%c",mp[b[j]]);
    49         }
    50         else
    51         { 
    52          for(int j=k-1;j>=k-m;j--)
    53          printf("%c",mp[b[j]]);
    54         }
    55         cout<<endl;    
    56 }
    57      return 0;
    58  }
  • 相关阅读:
    用户访问过的产品,在cookie记录产品id,id取得产品信息
    文件上传操作
    上次文件先创建目录,再上传到目录里面去
    解决PHPcms 2008 sp4 注册选择模型关闭后,注册不能自动登录的问题
    php输出表格的方法
    php中实现退后功能,不用历史记录
    PHP的substr_replace将指定两位置之间的字符替换为*号
    php算开始时间到过期时间的相隔的天数,同理可以实现相隔年,小时,分,秒等数
    不用js用php做tab选项卡
    再也回不去的从前
  • 原文地址:https://www.cnblogs.com/hsd-/p/5423490.html
Copyright © 2011-2022 走看看