HDU 3943 数位dp+二分
K-th Nya Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 3155 Accepted Submission(s): 1021
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.
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).
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).
38 400 1 1
10
1
2
3
4
5
6
7
8
9
10
47
74
147
174
247
274
347
374
Nya!
Nya!
题意:
求区间内第k个有且仅有x个4和y个7的数
代码:
//注意细节
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int t,x,y,bit[];
ll f[][][],P,Q;
ll dfs(int pos,int xx,int yy,int limit)
{
if(pos==) return (xx==&&yy==);
if(xx<||yy<) return ;
if(!limit&&f[pos][xx][yy]!=-) return f[pos][xx][yy];
int max_b=limit?bit[pos]:;
ll ans=;
for(int i=;i<=max_b;i++){
ans+=dfs(pos-,xx-(i==),yy-(i==),limit&&(i==max_b));
}
if(!limit) f[pos][xx][yy]=ans;
return ans;
}
ll solve(ll O)
{
int pos=;
while(O){
bit[++pos]=O%;
O/=;
}
return dfs(pos,x,y,);
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
printf("Case #%d:\n",cas);
memset(f,-,sizeof(f));
scanf("%lld%lld%d%d",&P,&Q,&x,&y);
ll tmp1=solve(P);
ll tmp2=solve(Q);
int n;ll k;
scanf("%d",&n);
while(n--){
scanf("%lld",&k);
if(tmp2-tmp1<k) { puts("Nya!");continue; }
ll l=P+,r=Q,ans;
while(l<=r){
ll mid=(l+r)>>;
ll tmp=solve(mid);
if(tmp-tmp1>=k) { ans=mid;r=mid-; }
else l=mid+;
}
printf("%lld\n",ans);
}
}
return ;
}
HDU 3943 数位dp+二分的更多相关文章
- HDU 3271 数位dp+二分
SNIBB Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- poj3208 Apocalypse Someday 数位dp+二分 求第K(K <= 5*107)个有连续3个6的数。
/** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. ...
- hihocoder #1301 : 筑地市场 数位dp+二分
题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostr ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...
- UPC 2223: A-Number and B-Number(数位DP+二分)
积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要 ...
- CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)
All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...
- hdu:2089 ( 数位dp入门+模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...
随机推荐
- 分布式高并发下全局ID生成策略
数据在分片时,典型的是分库分表,就有一个全局ID生成的问题.单纯的生成全局ID并不是什么难题,但是生成的ID通常要满足分片的一些要求: 1 不能有单点故障. 2 以时间为序,或者ID里包含时间 ...
- PyCharm配置SFTP远程调试Django应用
http://www.ithao123.cn/content-41747.html http://www.th7.cn/system/lin/201703/205998.shtml
- 王者荣耀交流协会互评Beta版本及答复功能改进建议、Bug修正
互评Beta版本 欢迎来怼团队博客园安卓APP Thunder团队爱阅app 探路者团队贪吃蛇 Hello World!团队项目空天猎 答复功能改进建议 答复其他各组给出的“就现有技术和工作量,不改变 ...
- JSON toBean Timestamp To Date 时间戳转日期
时间戳格式的时间从json转为date时 配置: import java.util.Date; import net.sf.ezmorph.object.AbstractObjectMorpher; ...
- Servlet以流的形式返回图片
代码: import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import ...
- 区别mouseover与mouseenter?
区别mouseover与mouseenter? * mouseover: 在移入子元素时也会触发, 对应mouseout,进入子元素的时候,父元素显示离开状态 * mouseenter: 只在移入当前 ...
- ES6 常用1
( (1)交换变量的值 ) [x, y] = [y, x]; ( (2)从函数返回多个值 // 返回一个数组function example() { return [1, 2, 3]; } var [ ...
- DataTable List 相互转换
This uses the FastMember's meta-programming API for maximum performance. If you want to restrict it ...
- 子类的实例给父类的引用 在编译器时候 jvm认为他是父类的实例 只会去寻找父类里面的方法 如果调用子类里面的属性或者方法时候 jvm会认为该引用并没有 所以会报错
- C#:system.collections.generic(泛型)
1. array是一个固定长度的,如果要动态的存储的话就不行了,虽然 System.Collections.ArrayList(),是一个动态的存储的容器,但是没有对存储中的数据进行一个约束,所以非泛 ...