zoukankan      html  css  js  c++  java
  • BestCoder Round #81 (div.2)Machine

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 using namespace std;
     5 
     6 char s[31];
     7 char arr[3]={'R','G','B'};
     8 long long ans[31];
     9 
    10 void ans1()
    11 {
    12     ans[0]=1;
    13     for(int j=1;j<31;j++)
    14     {
    15         ans[j]=1;
    16         for(int i=1;i<=j;i++)
    17             ans[j]*=3;
    18     }
    19 }
    20 int main()
    21 {
    22     long long t,m,n;
    23     scanf("%lld",&t);
    24     ans1();
    25     while(t--)
    26     {
    27         memset(s,'R',sizeof(s));
    28         scanf("%lld%lld",&m,&n);
    29         for(int i=1;i<=m;i++)
    30             s[i]=arr[n%ans[i]/ans[i-1]];
    31         for(int i=m;i>0;i--)
    32             printf("%c",s[i]);
    33         printf("
    ");
    34     }
    35     return 0;        
    36 }
    View Code

    红、绿、蓝分别表示0、1、2,每次操作就相当于+1,原问题就转化为求nnn的三进制

    表示的最低的mmm位,即求 nnn mod 3m3^m3m​​的三进制表示。

    复杂度 O(m)

  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/WDKER/p/5422775.html
Copyright © 2011-2022 走看看