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

Problem Description
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!
 
Author
hzhua

题意:

求区间内第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+二分的更多相关文章

  1. HDU 3271 数位dp+二分

    SNIBB Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  3. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

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

  5. hihocoder #1301 : 筑地市场 数位dp+二分

    题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostr ...

  6. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  7. UPC 2223: A-Number and B-Number(数位DP+二分)

    积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要 ...

  8. CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)

    All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...

  9. hdu:2089 ( 数位dp入门+模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...

随机推荐

  1. ansible软件2

    常用软件安装及使用目录  ansible使用1 第1章 copy模块 1.1 创建文件及写入内容 1. [root@m01 scripts]# ansible oldboy -m copy -a &q ...

  2. Beta发布 _thunder_文案+美工展示

    作业要求:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1366 团队介绍:thunder 组成员及各位博客地址: 1.王航:htt ...

  3. 20162319 实验二 Java面对对象程序设计 实验报告

    实验二 Java面向对象程序设计 实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5.了解设计模式 实验 ...

  4. C#中周,月,第几周,周开始结束时间de方法总结

    1.c#获取当前时间是本年的第几周,本月的第几周 private static int getWeekNumInMonth(DateTime daytime) { int dayInMonth = d ...

  5. 项目Beta冲刺(团队)第三天

    1.昨天的困难 记住密码打勾之后点击登录记住密码这四个字会变成省略号 点赞点击以后本应该呈现的爱心形状变成了方块 2.今天解决的进度 成员 进度 陈家权 私信模块探索ing,回复详情界面设计 赖晓连 ...

  6. Week2-作业1 《构建之法》1、2、16章观后感

    这几天阅读了<构建之法>中的几章,受益匪浅,刷新了很多我对软件工程的认知.这本书让我很惊喜,阅读起来不像其他书一样枯燥,有很多人物的设计,以及对话的形式,非常有趣. 第一章.概述 读完第一 ...

  7. Java& Vector与ArrayList区别

    在写java的时候,基本上都喜欢用arraylist,甚至我都不知道有个vector的存在.查了一下发现又是线程安全问题...咋个线程安全天天围着我转呢...多得阿里巴巴,让我开始认识java的所谓线 ...

  8. 用户数以及psp

    小组名称:好好学习 小组成员:林莉  王东涵   胡丽娜   宫丽君 项目名称: 记账本 alpha发布48小时以后用户数如何,是否达到预期目标,为什么,是否需要改进,如何改进(或理性估算). 首先我 ...

  9. IE盒模型与W3C盒模型区别

    前两天被人问到,叫我解释一下标准盒模型与IE盒模型,额,当时只能说,知道一点,但是没有深入的去探讨过,所以下来之后就自己写了例子,亲自去验证并且查看了网上的一些资料,现将其整理如下: 一.css盒模型 ...

  10. 读书笔记-《Java核心技术卷I-基础知识》

    1.定时器Timer类 构造定时器时,需要设置一个时间间隔,并告知定时器,当到达时间间隔时需要做什么操作.定时器需要知道调用哪一个方法,并要求传递的对象所属的类实现了java.awt.event包的A ...