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的板子敲就行 ...
随机推荐
- 第一讲:SQL语言概述
SQL语言是集DDL.DML和DCL于一体的数据库语言. SQL语言之DDL:定义数据库 SQL语言之DML:操纵数据库 一.功能概述 SQL语言主要由以下9个单词引导的操作语句来构成,但每一条语句都 ...
- java判断字符串编码
是 public static String getEncoding(String str){ String encoding = "UTF-8"; try { if (str.e ...
- 从数据库表导出为excel表格
package com.test.daotest; import java.io.FileNotFoundException; import java.io.FileOutputStream; i ...
- 二级制包安装Tomcat 与 RPM包安装Tomcat
1:下载二级制包 wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.47/bin/apache-tomcat-8.0.47.tar.g ...
- docker weave安装
1.升级内核到3.10.0以上,安装iproute22.安装 0.80版本:#wget -O /usr/local/bin/weave https://raw.githubusercontent.co ...
- mysql 读写锁
1. 表读锁 lock table tablename read; 例如: 从上图中可以看到,当给表a加了读锁之后,该进程本身对表a是可读的,但是不可写,再看在另外一个进程中: 在另外一个进程中表a也 ...
- 谁能告诉delphi7 的updatebatch使用属性说明?
谁能告诉delphi7 的updatebatch使用属性说明? ADODataSet1.UpdateBatch(arAll); 就是提交你的数据集到数据库 arCurrentOnly the upda ...
- Java开发中的23种设计模式详解(转载)
前学习过一段时间的设计模式,总是感觉学习的不够清楚.现在再重新复习一下,原文地址:https://blog.csdn.net/doymm2008/article/details/13288067 一. ...
- param 是获取请求传递过来的参数
- 对HashMap的理解(三):ConcurrentHashMap
HashMap不是线程安全的.在并发插入元素的时候,有可能出现环链表,让下一次读操作出现死循环.避免HashMap的线程安全问题有很多方法,比如改用HashTable或Collections.sync ...