BestCoder Round #81 (div.2)1001
Machine
There is a machine with m(2≤m≤30)m (2\leq m\leq 30)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)n (1\leq n< {2}^{63})n(1≤n<263) times?
There are multiple test cases. The first line of input contains an integer T(1≤T≤15)T (1\leq T\leq 15)T(1≤T≤15) indicating the number of test cases. For each test case:
The only line contains two integers m(2≤m≤30)m (2\leq m\leq 30)m(2≤m≤30) and n(1≤n<263)n (1\leq n< {2}^{63})n(1≤n<263).
For each test case, output the colour of m bulbs from left to right. R indicates red. G indicates green. B indicates blue.
2
3 1
2 3
RRG
GR
题目大意:
就是有一排灯泡,初始时每一个灯泡的颜色都是红色,同时有一个Button,每点一次,就会时最右边的灯泡的颜色都会发生变化,
变化规则为R->G->B->R,周而复始进行循环,但是当灯泡是从B->R时,它左边的灯泡的颜色也会相应的发生变化。
思路分析:好久没敲代码了,手生的不行,被这么一道水题坑了半天,首先是输入的时候,n的范围很大,应该用lld或者I64d进行
输入,另外n值这么大,我竟然第一想法是模拟一遍,orz,超时了,每一个灯泡的最终颜色只与n%3的余数有关,这样进行判断无疑是
最省时间的。
代码:
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn=35;
char bulb[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
__int64 m,n;
scanf("%I64d%I64d",&m,&n);
memset(bulb,'R',sizeof(bulb));
for(int i=0;i<m;i++)
{
if(n==0) break;
if(n%3==0) bulb[i]='R';
if(n%3==1) bulb[i]='G';
if(n%3==2) bulb[i]='B';
n/=3;
}
for(int i=m-1;i>=0;i--)
printf("%c",bulb[i]);
printf("\n");
}
return 0;
}
BestCoder Round #81 (div.2)1001的更多相关文章
- BestCoder Round #81 (div.2) 1004 String(动态规划)
题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)
题目:Click here 题意:bestcoder上面有中文题目 #include <iostream> #include <cstdio> #include <cst ...
- BestCoder Round #81 (div.2) 1003 String
题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...
- BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...
- BestCoder Round #81 (div.2)C String
总体思路好想,就是在找K个不同字母的时候,卡时间. 看了大神代码,发现goto的!!!!998ms #include<cstdio> #include<cstring> #in ...
- BestCoder Round #81 (div.2) B Matrix
B题...水题,记录当前行是由原矩阵哪行变来的. #include<cstdio> #include<cstring> #include<cstdlib> #inc ...
- BestCoder Round #81 (div.1)A
水题...就是n的三进制后m位 #include<cstdio> #include<cstring> #include<cstdlib> #include<i ...
- BestCoder Round #81 (div.2)
HDU:5670~5764 A题: 是一个3进制计数: #include <bits/stdc++.h> using namespace std; ]; int calc(long lon ...
随机推荐
- jQuery1.9(辅助函数)学习之——.serialize();
$("form").serialize(); 返回一个String 描述: 将用作提交的表单元素的值编译成字符串,这个方法不接受任何参数. .serialize(); 方法使用标 ...
- 使用“bulk insert ”进行批量插入数据
本文转自csdn中文章,再次感谢他给我们分享. Bulk Insert命令详细 BULK INSERT以用户指定的格式复制一个数据文件至数据库表或视图中.语法: BULK INSERT [ [ 'da ...
- 利用css3-animation来制作逐帧动画
前言 趁着还没有元旦之前先码一篇文章,不然到时候估计又被各种虐了,所以趁现在还有力气先来一篇.今天来聊聊css3中的动画属性animation,对这个属性懵懂是在很早的时候有前辈用这个 animati ...
- iOS学习之页面之间传值的方式总结
传值三种场景: 1.属性传值(从前往后传) 需求:第二个界面标签显示第一个界面输入框文字. 第一步, 在前一个界面定义属性. (语义属性声明为copy); 第二步, 在进入下一个界面之前,给属性传入数 ...
- arm get_vector_swi_address
unsigned long* get_vector_swi_addr() { const void *swi_addr = 0xFFFF0008; unsigned ; unsigned ; unsi ...
- 解决ScrollView 与ListView共存显示不完全的问题
ScrollView与ListView共存会存在滚动的问题,并且ListView只显示一个半Item. 当ListView的高度设定一定的值时,ListView同样地会显示对应的高度的Item. 因此 ...
- javascript 中ASCII字符值转换
char-->ascii var a = "123"; a.charAt(1).charCodeAt();ascii-->char String.fro ...
- logstash 发送zabbix告警
<pre name="code" class="html">[elk@dr-mysql01 test]$ cat t1.conf input { s ...
- 关于Set Nocount ON的性能 |c#调用存储过程的返回值总是-1
原文地址:http://www.tuicool.com/articles/qe6BZbR 也许因为它太过于简单,自己一直没能好好关注这个语句,只记得"只是"提高点性能而已.有时会在存储过程中写上几句, ...
- Exchange Server 2010/2013功能差异