程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> hdu 5670 Machine(BC規律題)

hdu 5670 Machine(BC規律題)

編輯:關於C

題目鏈接: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): 451Accepted Submission(s): 266

Problem Description There is a machine withm(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
pushedn(1≤n<263)times?
Input There are multiple test cases. The first line of input contains an integerT(1≤T≤15)indicating the number of test cases. For each test case:

The only line contains two integersm(2≤m≤30)andn(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次變換一次,以此類推。。。。 詳見代碼。
#include  #include  #include  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; } 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved