K-th Nya Number

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on HDU. Original ID: 3943
64-bit integer IO format: %I64d      Java class name: Main

Arcueid likes nya number very much.
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 first line contains a positive integer T (T<=100), indicates there are T test cases.
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 test case, display its case number and then print N lines.
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

 
解题:数位dp+二分
 #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的更多相关文章

  1. HDU 3943 数位dp+二分

    K-th Nya Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) ...

  2. hdu 3943 经典数位dp好题

    /* 题意:求出p-q的第j个nya数 数位dp,求出p-q的所有nya数的个数很好求,但是询问求出最终那个第j个值时是我不会求了看了下别人的思路 具体就是把p-q的第j个转化成0-q的第low+j个 ...

  3. HDU 3943 K-th Nya Number(数位DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3943 题目大意:求出区间 (P,Q] 中找到第K个满足条件的数,条件是该数包含X个4和Y个7 Samp ...

  4. 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 ...

  5. 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猜 ...

  6. hdu 4006 The kth great number (优先队列)

    /********************************************************** 题目: The kth great number(HDU 4006) 链接: h ...

  7. HDU 5122 K.Bro Sorting(模拟——思维题详解)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5122 Problem Description Matt's friend K.Bro is an A ...

  8. hdu 4006 The kth great number(优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 题目大意: 第一行 输入 n k,后有 n 行,对于每一行有两种状态 ,①“I x” : 插入 ...

  9. hdu 4006 The kth great number

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4006 思路:利用优先队列的性质,将数据存入后会自动对数据进行排序 #include<stdlib ...

随机推荐

  1. 基于.net core封装的xml序列化,反序列化操作

    需求: 由于在.net core中去除了Xml序列化XmlSerializer操作类.因此,在于一此数据传输当中出,需要用到对xml格式字符串的处理问题.因此封装了一个xml序列化与反序列化操作的类库 ...

  2. mint-ui pull down不起作用及解决方案

    <template> <div style="min-height:200px"> <mt-loadmore :top-method="lo ...

  3. webpack(1)

    在网页中会引用哪些常见的静态资源? JS .js .jsx .coffee .ts(TypeScript 类 C# 语言) CSS .css .less .sass .scss Images .jpg ...

  4. 【javascript】操作给定的二叉树,将其变换为源二叉树的镜像。

    操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 ...

  5. 将生成的Excel表发送到邮箱

    本文接上一篇,将得到的Excel表发送到邮箱.. 在上一篇中,本人使用的是直接从数据库中获取数据,然后包装成Excel表.现在将该Excel表发送到目的邮箱,如果需要跟上篇一样,定时每天某时刻发送,就 ...

  6. uvm_misc——杂货铺(miscellaneous)

    uvm_misc 是个很有意思的文件夹,本质上就是个UVM的杂货铺,包含一些很重要的class, task, function, 但不知道给归类到哪儿,所以,uvm_misc就很好地承担了这个任务,几 ...

  7. SQL 时间日期函数

    1.获取当前日期GetDate getdate()函数以datetime数据类型的格式返回当前SQLServer服务器所在计算机的日期和时间.其语法格式为getdate().返回值舍入到最近的秒小数部 ...

  8. ubuntu 16.0 利用ant编译 hadoop-eclipse-plugins2.6.0

    折腾了两天,抱着不放弃的精神,我终于编译出我自己所需的hadoop中在eclipse中的插件 在网上下载的可能因为版本不一致,在编译的时候出现各种各样的问题,包括你的eclipse版本和hadoop版 ...

  9. Lesson2

    #ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/ ...

  10. Tensorflow_入门学习_2_一个神经网络栗子

    3.0 A Neural Network Example 载入数据: from tensorflow.examples.tutorials.mnist import input_data mnist ...