码迷,mamicode.com
首页 > 其他好文 > 详细

POJ1613 147/思维题

时间:2016-12-17 13:34:17      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:max   ace   long   tps   names   main   pac   using   链接   

题目链接[https://www.oj.swust.edu.cn/problem/show/1613]

题意:输出第K小的由1、4、7数字组成的数字。

解题过程:1、4、7、11、14、17、41、44、47。。。。。。。找规律。

#include<bits/stdc++.h>
using namespace std;
typedef long long  LL;
const int maxn = 30;
const int mod = 1e9+7;
int a[5]={0,1,4,7};
int ans[maxn];
int k;
int main ()
{
    while(~scanf("%d",&k))
    {
        int len=0;
        while(k)
        {
            int t=k%3;
            if(t==0) t=3;
            ans[++len]=a[t];
            k=(k-t)/3;
        }
        for(int i=len;i>=1;i--)
            printf("%d",ans[i]);
        printf("\n");
    }
    return 0;
}

 

POJ1613 147/思维题

标签:max   ace   long   tps   names   main   pac   using   链接   

原文地址:http://www.cnblogs.com/pealicx/p/6189431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!