栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3208 Apocalypse Someday

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3208 Apocalypse Someday

#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;typedef long long val_t;const int MAX_DIG = 10, MAX_NUM = 9, STATE = 4;const int trans[4][10] = {    {0, 0, 0, 0, 0, 0, 1, 0, 0, 0},    {0, 0, 0, 0, 0, 0, 2, 0, 0, 0},    {0, 0, 0, 0, 0, 0, 3, 0, 0, 0},    {3, 3, 3, 3, 3, 3, 3, 3, 3, 3}};val_t f[MAX_DIG + 1][STATE];int T, n;int main() {    f[0][3] = 1;    for (int i = 1; i <= MAX_DIG; i ++)        for (int j = 0; j < STATE; j ++) for (int k = 0; k <= MAX_NUM; k ++)     f[i][j] += f[i - 1][trans[j][k]];    for (scanf("%d", &T); T -- && scanf("%d", &n) != EOF; ) {        int dig = 0;        for (int i = 1; i <= MAX_DIG; i ++) if (f[i][0] >= n) {     dig = i;     break; }        int st = 0;        for (int i = dig; i >= 1; i --) { int cnt = 0; for (int j = 0; j <= MAX_NUM; j ++) {     cnt += f[i - 1][trans[st][j]];     if (cnt >= n) {         printf("%d", j);         cnt -= f[i - 1][trans[st][j]];         n -= cnt;         st = trans[st][j];         break;     } }        }        printf("n");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380054.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号