Apocalypse Someday poj 3208
题目
问你在所有包含666的数中,第n大的是多少。(1 ≤ n ≤ 50,000,000) 。开头几个是666, 1666, 2666, 3666, 4666, 5666…
分析
套路
先dp预处理,再一位位的填数。
code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>#define N 50
#define LL long longusing namespace std;long long f[N][4];void dp()
{f[0][0]=1;for (int i=1;i<=20;i++){f[i][0]=9*f[i-1][0]+9*f[i-1][1]+9*f[i-1][2];f[i][1]=f[i-1][0];f[i][2]=f[i-1][1];f[i][3]=f[i-1][2]+10*f[i-1][3];}
}int T,ans;
int main()
{freopen("data.in","r",stdin);freopen("data.out","w",stdout);scanf("%d",&T);dp();while (T--){int x; scanf("%d",&x);int m;for (m=1;m<=20;m++)if (f[m][3]>=x) break;long long num=0;int k=0;for (int i=m;i>=1;i--){int j;for (j=0;j<=9;j++){if (j==6||k==3){long long cnt=0;if (j==6) cnt=f[i-1][3];for (int l=max(3-k-(j==6),0);l<3;l++)cnt+=f[i-1][l];if (cnt+num<x) num+=cnt;else break;}if (j!=6) {if (f[i-1][3]+num<x) num+=f[i-1][3];else break;}}printf("%d",j);if (k<3){if (j==6) k++;else k=0;}}printf("\n");}
}
Apocalypse Someday poj 3208相关推荐
- poj 3208 Apocalypse Someday 数位dp+二分答案
Apocalypse Someday Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 2203 Accepted: 11 ...
- POJ 3208 Apocalypse Someday
HyperlinkHyperlinkHyperlink http://poj.org/problem?id=3208 DescriptionDescriptionDescription 定义包含三个连 ...
- poj 3208 Apocalypse Someday(数位dp)
题意:给定n,输出第n大包含666的数字. 分析:数位dp,详见<算法竞赛进阶指南>P342-344. 代码: #include<iostream> #include<c ...
- #数位dp#poj 3208 Apocalypse Someday
题目 定义一种神奇的数当且仅当数位上至少有3个6,问第n个神奇的数是多少 分析 那么可以预处理出由i位数字构成的魔鬼/非魔鬼数, f[i][0]=9∗(f[i−1][0]+f[i−1][1]+f[i− ...
- Poj 3208 Apocalypse Someday(数位dp + 二分)
题目大意: 有三个连续的6在一起的数就是beast数,前几个beast数是:666,1666,2666,- T组数据,每组询问排名为n的beast的数是什么? 解题思路 第一眼看到懵逼了,不是 ...
- Apocalypse Someday(POJ-3208)
Problem Description The number 666 is considered to be the occult "number of the beast" an ...
- POJ3208:Apocalypse Someday
题目描述 The number 666 is considered to be the occult "number of the beast" and is a well use ...
- poj3208 Apocalypse Someday
Description The number 666 is considered to be the occult "number of the beast" and is a w ...
- poj3208 Apocalypse Someday (数位dp + 二分)
The number 666 is considered to be the occult "number of the beast" and is a well used num ...
最新文章
- OpenCV中使用YOLO对象检测
- C#递归获取JSON所有键值对
- OpenCV中的CV_IMPL是什么意思?
- 监护仪系统都是Linux吗,基于Linux和MiniGUI的心电监护仪设计
- html 5 canvas flash,为什么使用HTML5 Canvas创建内容比使用Flash创作要复杂得多?
- 洛谷P1450:硬币购物(背包、容斥)
- win8服务器无法安装win7系统安装,win8怎么安装win7 win8改win7教程详解【图文】
- 基于meanshift的手势跟踪与电脑鼠标控制(手势交互系统)
- 五一假期期间 全国快递包裹揽投量同比增长约四成
- DDA数值微分法详解
- Axure RP8从入门到精通手册
- 怎样配置 Docker IPv6 ?
- 电子签名、数字签名、数字证书、电子签章、电子印章的概念和区别
- C++汉字转拼音( 转)
- 股票python量化交易002-常见量化指标(基本面)
- 高通Display架构
- Windform对sql数据库进行操作
- text-align 和 align的区别
- 前端VUE面试题总结
- 3032. 是坚挺数吗?
热门文章
- 《前端》权限链接--vue前端权限控制方案详解附demo_feiyu_may的博客-CSDN博客_vue 前端权限
- 如何巧妙的应对突如其来的电话面试呢
- 【笔记】注意分配阅读笔记
- 软考A计划-试题模拟含答案解析-卷十七
- Ubuntu 下安装 SVN 服务端
- 软考A计划-试题模拟含答案解析-卷十六
- 机器学习集成方法Bagging、Boosting和Stacking
- Oracle 保留两位小数详解
- RestTemplate发送form-data请求上传rul资源文件及对象参数
- Senparc.Weixin.MP SDK 微信公众平台开发教程(六):了解MessageHandler