HDU 5670 Machine

本文提供了一种使用递归思想解决HDU 5670问题的方法,通过将数字转换为三进制并映射到RGB颜色的方式输出结果。为了简化输出流程,采用数组保存中间结果,最后逆序输出。该题解使用C++语言实现。

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5670

思路:用递归实现输出在后,比较麻烦,保存在数组里,倒着输出数组比较方便

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int deng[35];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(deng,0,sizeof(deng));
        int m;
        unsigned long long n;
        cin>>m>>n;
        int len=0;
        while(n!=0)
        {
            deng[len++] = n % 3;
            n /= 3;
        }
        for(int i=m-1; i>=0; i--)
        {
            if(deng[i] == 0)
                printf("R");
            else if(deng[i] == 1)
                printf("G");
            else if(deng[i] == 2)
                printf("B");
        }
        printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值