poj 3909 二分
来源:互联网 发布:淘宝代销发货怎么联系 编辑:程序博客网 时间:2024/06/10 04:47
先用两个dfs暴力求出所有的lucky numbers,然后二分lucky number数组的下标,求出答案
View Code
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef __int64 lld;
vector<lld> lu,res;
int tot;
void dfs(lld num,int de){
if(de==12) return ;
lu.push_back(num);
dfs(num*10+4,de+1);
dfs(num*10+7,de+1);
}
void dfs1(int x,lld num){
for(int i=x;i<lu.size();i++){
if(1e12/num<lu[i]) return;
res.push_back(num*lu[i]);
dfs1(i,num*lu[i]);
}
}
void init(){
lu.clear();res.clear();
dfs(4,0);
dfs(7,0);
sort(lu.begin(),lu.end());
dfs1(0,1);
sort(res.begin(),res.end());
tot=unique(res.begin(),res.end())-res.begin();
}
int main(){
init();
int t;
lld a,b;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&a,&b);
int l=lower_bound(res.begin(),res.begin()+tot,a)-res.begin();
int r=upper_bound(res.begin(),res.begin()+tot,b)-res.begin();
printf("%d\n",r-l);
}
}
- poj 3909 二分
- POJ 3909 Lucky numbers 深搜预存+二分
- poj (3343)二分匹配+二分
- POJ 3233 二分二分矩阵
- poj 3685 二分套二分
- poj 3685 二分套二分
- POJ 二分算法
- POJ 3258 二分算法
- poj 2060 二分匹配
- poj 3273 (二分)
- poj 3273(二分。。。很水。。。。)
- poj 3258(二分。。。)
- poj 1693 二分图
- POJ 3122 Pie 二分
- poj 3258 二分 过河
- POJ 3122 Pie 二分
- poj 3258 还是二分
- poj 1274(二分匹配)
- 无源汇上下界网络流 zju zoj 2314
- zju zoj 3573 查询线段最大覆盖次数
- zoj 3574 求给定区间内n条线段能将区间内的区域划分成几个区域
- zoj 2974 矩阵连乘
- hdu 3245 zoj zju 3188 树形DP
- poj 3909 二分
- poj 3342 树形DP
- 一组数,求最少交换几次使得数组有序
- zoj 1440 zju
- poj 2631 poj 1985 树的直径 树的最长链
- poj 2342 树形DP
- poj 3352 边双连通
- zoj 3583
- poj 1637 求混合图的欧拉回路