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 ...
随机推荐
- ASP.NET环境下集成CKEditor与CKEditor实现文件上传
1.从http://ckeditor.com网站上下载ckeditor_aspnet_3.6.4与ckfinder_aspnet_2.4; 2.解压下载的文件ckeditor_aspnet_3.6.4 ...
- ThinkPHP内置函数详解D、F、S、C、L、A、I
单字母函数D.F.S.C.L.A.I 他们都在ThinkPHP核心的ThinkPHP/Mode/Api/functions.php这个文件中定义. 下面我分别说明一下他们的功能: D() 加载Mode ...
- pyqt5通过文本对话框打开文件
点击按钮,打开文本对话框,找一人文件,打开并显示内容 QFIleDialog ...
- GO语言可以直接输出数组
package main import "fmt" func main(){ ]int ;i<;i++{ arr[i]=i } fmt.Printf("%v&quo ...
- iOS自动打发布包-备用
#!/bin/bash # autoPublishH.sh# ## Created by 刘志托 liu on 12-2-8.# Copyright (c) 2012年 null. All r ...
- Feedly订阅Blog部落格RSS网摘 - Blog透视镜
网络信息爆炸的时代,如何更有效率地阅读文章,订阅RSS网摘,可以快速地浏览文章标题,当对某些文章有兴趣时,才点下连结连到原网站,阅读更详细的文章,Feedly Reader阅读器除了提供在线版订阅RS ...
- Linux企业级项目实践之网络爬虫(22)——编写爬虫系统服务控制脚本
需求:1.可通过 service spider start|stop|status|restart 命令对服务进行控制2.spider服务可开机自启动 start() { echo "sta ...
- Javascript中&&和&,||和|运算符两个不同点
1.性能上的比较 如果&&的第一个运算数是false,就不再考虑第二个运算数,直接返回false:如 果||的第一个运算数是true,也不再考虑第二个运算数,直接返回true.& ...
- 符号表实现(Symbol Table Implementations)
符号表的实现有很多方式,下面介绍其中的几种. 乱序(未排序)数组实现 这种情况,不需要改变数组,操作就在这个数组上执行.在最坏的情况下插入,搜索,删除时间复杂度为O(n). 有序(已排序)数组实现 这 ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(1)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选,其余章节将陆续放出.上一篇:Wow ...