POJ 1906

#include <iostream>
#include <string>
#define MAXN 150
using namespace std;

int _m[MAXN];

string p[65] = {
            "1",
            "3",
            "9",
            "27",
            "81",
            "243",
            "729",
            "2187",
            "6561",
            "19683",
            "59049",
            "177147",
            "531441",
            "1594323",
            "4782969",
            "14348907",
            "43046721",
            "129140163",
            "387420489",
            "1162261467",
            "3486784401",
            "10460353203",
            "31381059609",
            "94143178827",
            "282429536481",
            "847288609443",
            "2541865828329",
            "7625597484987",
            "22876792454961",
            "68630377364883",
            "205891132094649",
            "617673396283947",
            "1853020188851841",
            "5559060566555523",
            "16677181699666569",
            "50031545098999707",
            "150094635296999121",
            "450283905890997363",
            "1350851717672992089",
            "4052555153018976267",
            "12157665459056928801",
            "36472996377170786403",
            "109418989131512359209",
            "328256967394537077627",
            "984770902183611232881",
            "2954312706550833698643",
            "8862938119652501095929",
            "26588814358957503287787",
            "79766443076872509863361",
            "239299329230617529590083",
            "717897987691852588770249",
            "2153693963075557766310747",
            "6461081889226673298932241",
            "19383245667680019896796723",
            "58149737003040059690390169",
            "174449211009120179071170507",
            "523347633027360537213511521",
            "1570042899082081611640534563",
            "4710128697246244834921603689",
            "14130386091738734504764811067",
            "42391158275216203514294433201",
            "127173474825648610542883299603",
            "381520424476945831628649898809",
            "1144561273430837494885949696427",
            "3433683820292512484657849089281"
};

int fun(unsigned long long num);

int main()
{
    //freopen("acm.acm","r",stdin);
    unsigned long long  num;
    unsigned long long  tem;
    int index;
    int i;
    while(cin>>num)
    {
        if(num == 0)
        {
            break;
        }
    //    cout<<num<<endl;
        if(num == 1)
        {
            cout<<"{ }"<<endl;
        }
        else
        {
            index = fun(num-1);
            cout<<"{ ";
            //cout<<index<<endl;
            int j = 0;
            for(i = 0; i < index-1; ++ i)
            {
                if(_m[i] == 1)
                {
                    cout<<p[j]<<", ";
                }
                ++ j;
            }
            if(_m[i] == 1)
            {
                cout<<p[j];

            }
            cout<<" }"<<endl;
        }
    }
}

int fun(unsigned long long num)
{
    int i = 0;
    while(num)
    {
        _m[i ++] = num%2;
        num /= 2;
    }
    return i;
}
时间: 2024-11-15 06:43:36

POJ 1906的相关文章

poj 3130 How I Mathematician Wonder What You Are!

How I Mathematician Wonder What You Are! Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3568   Accepted: 1906 Description After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician uses a big

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

poj题库分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (

Poj 题目分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目分类(转)

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

北大POJ题库使用指南

原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列组合).递推关系.质因数法 6.计算几何 //凸壳.同等安置矩形的并的面积与周长.凸包计算问题 8.模拟 9.数据结构 //并查集.堆.树形结构 10.博弈论 11.CD有正气法题目分类: 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&