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 ...
随机推荐
- COGS 1578. 次小生成树初级练习题
☆ 输入文件:mst2.in 输出文件:mst2.out 简单对比时间限制:1 s 内存限制:256 MB [题目描述] 求严格次小生成树 [输入格式] 第一行包含两个整数N 和M,表 ...
- UVALive 4287 Proving Equivalence (强连通分量)
把证明的关系看出一张图,最终就是要所有的点都在至少一个环中.环的判断和度数有关. 用tarjan找强连通分量,在一个强连通分量点已经等价缩点以后形成一个DAG,计算入度为0的点数a, 出度为0的b,取 ...
- core 下使用 autofac
依赖注入小伙伴们比较常了,这里只说core 下autofac依赖注入的使用 ,不多费话,直接代码. 在 Startup.cs里 public void ConfigureServices(IServi ...
- video 的使用
video ui给了默认的暂停图片 利用video自身的属性很难达到效果 这里自己写了个 简单记录下 <div class="cg-container video-img" ...
- Bootstrap历练实例:链接样式按钮
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- javaEE(12)_数据库连接池
一.直接获取数据库连接和通过池获取示意图: 二.编写数据库连接池 1.实现DataSource接口,并实现连接池功能的步骤: •在DataSource构造函数中批量创建与数据库的连接,并把创建的连接加 ...
- swift-通知的基本使用
swift-通知的基本使用 //通知的使用 1.发通知.(以这条通知为例,通知名字:nickNameNotification 通知参数:title) NSNotificationCenter.de ...
- 前端vue 里的tab切换 减少dom操作
<div class="vuedemo"> <div class="all"> <div class="tabone&q ...
- bzoj5138 [Usaco2017 Dec]Push a Box
题目描述: bz luogu 题解: 暴力可以记录$AB$位置转移,这个时候状态是$n^4$的,无法接受. 考虑只记录$A$在$B$旁边时的状态,这个时候状态时$n^2$的. 所以说转移有两种,一种是 ...
- 【Java_基础】java类加载过程与双亲委派机制
1.类的加载.连接和初始化 当程序使用某个类时,如果该类还未被加载到内存中,则系统会通过加载.连接.初始化三个步骤来对类进行初始化.如果没有意外,jvm将会连续完成这三个步骤,有时也把这三个步骤统称为 ...