HDU 3943 K-th Nya Number
K-th Nya Number
This problem will be judged on HDU. Original ID: 3943
64-bit integer IO format: %I64d Java class name: Main
A nya number is the number which
has exactly X fours and Y sevens(If X=2 and Y=3 , 172441277 and 47770142
are nya numbers.But 14777 is not a nya number ,because it has only 1
four).
Now, Arcueid wants to know the K-th nya number which is greater than P and not greater than Q.
Input
The second line contains 4 non-negative integers: P,Q,X and Y separated by spaces.
( 0<=X+Y<=20 , 0< P<=Q <2^63)
The third line contains an integer N(1<=N<=100).
Then here comes N queries.
Each of them contains an integer K_i (0<K_i <2^63).
Output
For each query, output a line contains an integer number, representing the K_i-th nya number in (P,Q].
If there is no such number,please output "Nya!"(without the quotes).
Sample Input
1
38 400 1 1
10
1
2
3
4
5
6
7
8
9
10
Sample Output
Case #1:
47
74
147
174
247
274
347
374
Nya!
Nya!
Source
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = ;
LL dp[maxn][maxn][maxn];
int bt[maxn],x,y;
LL dfs(int len,int a,int b,bool flag){
if(len == -) return a == x && y == b;
if(!flag && dp[len][a][b] != -) return dp[len][a][b];
int u = flag?bt[len]:;
LL ans = ;
for(int i = ; i <= u; ++i){
if(i == ) ans += dfs(len-,a + ,b,flag&&i == u);
else if(i == ) ans += dfs(len-,a,b + ,flag&&i==u);
else ans += dfs(len-,a,b,flag&&i==u);
}
if(!flag) dp[len][a][b] = ans;
return ans;
}
LL solve(LL x){
int cnt = ;
while(x){
bt[cnt++] = x%;
x /= ;
}
return dfs(cnt - ,,,true);
}
int main(){
int kase,m,cs = ;
scanf("%d",&kase);
while(kase--){
LL P,Q,K;
scanf("%I64d%I64d%d%d",&P,&Q,&x,&y);
memset(dp,-,sizeof dp);
scanf("%d",&m);
printf("Case #%d:\n",cs++);
LL tmp = solve(P);
while(m--){
scanf("%I64d",&K);
K += tmp;
LL low = P + ,high = Q,ans = -;
while(low <= high){
LL mid = (low + high)>>;
if(solve(mid) >= K){
ans = mid;
high = mid - ;
}else low = mid + ;
}
if(ans == -) puts("Nya!");
else printf("%I64d\n",ans);
}
}
return ;
}
HDU 3943 K-th Nya Number的更多相关文章
- HDU 3943 数位dp+二分
K-th Nya Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) ...
- hdu 3943 经典数位dp好题
/* 题意:求出p-q的第j个nya数 数位dp,求出p-q的所有nya数的个数很好求,但是询问求出最终那个第j个值时是我不会求了看了下别人的思路 具体就是把p-q的第j个转化成0-q的第low+j个 ...
- HDU 3943 K-th Nya Number(数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3943 题目大意:求出区间 (P,Q] 中找到第K个满足条件的数,条件是该数包含X个4和Y个7 Samp ...
- HDU - 4006 The kth great number multiset应用(找第k大值)
The kth great number Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming ...
- ACM-ICPC 2016 大连赛区现场赛 K. Guess the number && HDU 5981(思维+DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5981 题意:A在[L, R]之间随机选取一个数X,之后B来猜这个数,如果猜的数比X小,那么A就告诉B猜 ...
- hdu 4006 The kth great number (优先队列)
/********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...
- HDU 5122 K.Bro Sorting(模拟——思维题详解)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5122 Problem Description Matt's friend K.Bro is an A ...
- hdu 4006 The kth great number(优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...
- hdu 4006 The kth great number
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...
随机推荐
- 在腾讯云centOs系统上安装nginx
1.安装nginx 下载:wget http://nginx.org/download/nginx-1.8.1.tar.gz 解压:tar -zxvf nginx-1.8.1.tar.gz 安装编译源 ...
- 2018百度之星初赛(A)2 度度熊学队列
思路: 记录一下c++ stl中的双向链表list的各种用法. https://blog.csdn.net/fanyun_01/article/details/56881515 实现: #includ ...
- SQL Server 2008添加字段成功,但提示列名无效
在sql后查询,给现有表添加一个字段,即执行sql语句: alter table [sxrq_1108].[dbo].[公司周报表详情] add 总计 int default 0 然后在上述sql查语 ...
- NF!=1
NF表示列数,不等于1表示列数不为1列
- Android学习总结(五)———— BroadcastReceiver(广播接收器)的基本概念和两种注册广播方式
我们学完了Android四大组件的Activity和Service了,接下来我们一起来学习Android四大组件的第三个吧:BroadcastReceiver(广播接收者),计划如下图: 一.Broa ...
- webpack前端构建工具学习总结(四)之自动化生成项目中的html页面
接续上文:webpack前端构建工具学习总结(三)之webpack.config.js配置文件 插件的介绍文档:https://www.npmjs.com/package/html-webpack-p ...
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
解决方案: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 作用://取消数据库配置 但是 在用到数据库的时候记 ...
- vue 动态合并单元格、并添加小计合计功能
1.效果图 2.后台返回数据格式(平铺式) 3.后台返回数据后,整理所需要展示的属性存储到(items)数组内 var obj = { "id": curItems[i].id, ...
- Docker基础内容之网络基础
网络命名空间基本原理 单机版多容器实例网络交互原理 在宿主机上面打开两张网卡eth0与eth1,打通两张网卡的链路 在test1上面启动一个veth网卡,创建一个namespace:并桥接到eth0上 ...
- struts2的单个文件上传
本文主要两种方式,一:通过 FileUtils.copyFile(file, savefile);方法复制:二:通过字节流方式复制 web.xml <?xml version="1.0 ...