HDU 4343
二分加贪心,水过了。贪心是因为,不能存在覆盖,当存在覆盖时,留小坐标的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 300100
using namespace std; struct Point{
int left,right;
}pl[N]; int query[N/3][2]; bool cmp(Point a,Point b){
if(a.right<b.right)
return true;
return false;
} int find_index(int a,int n){
int l=0; int r=n-1;
int ans=-1;
while(l<=r){
int mid=(l+r)/2;
if(pl[mid].right<=a){
ans=mid;
l=mid+1;
}
else r=mid-1;
}
return ans;
} int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=0;i<n;i++)
scanf("%d%d",&pl[i].left,&pl[i].right);
for(int i=1;i<=m;i++){
scanf("%d%d",&query[i][0],&query[i][1]);
}
sort(pl,pl+n,cmp);
for(int i=1;i<=m;i++){
int a=query[i][0],b=query[i][1];
int bgn=find_index(a,n);
int ans=0;
int pos=a;
for(int k=bgn+1;k<n;k++){
if(pl[k].right<=b){
if(pl[k].left>=pos){
ans++;
pos=pl[k].right;
}
}
else break;
}
printf("%d\n",ans);
}
}
return 0;
}
HDU 4343的更多相关文章
- HDU 4343 贪心
D - Interval queryTime Limit: 1.5 Sec Memory Limit: 256 MB Description This is a very simple questio ...
- HDU 4343 D - Interval query 二分贪心
D - Interval queryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...
- 【HDU 4343】Interval query(倍增)
BUPT2017 wintertraining(15) #8D 题意 给你x轴上的N个线段,M次查询,每次问你[l,r]区间里最多有多少个不相交的线段.(0<N, M<=100000) 限 ...
- HDU 4343 Interval query(贪心 + 倍增)
题目链接 2012多校5 Problem D 题意 给定$n$个区间,数字范围在$[0, 10^{9}]$之间,保证左端点严格大于右端点. 然后有$m$个询问,每个询问也为一个区间,数字范围在$[ ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- vmware mac 分辨率设置
1.安装vmware tool 2.关闭虚拟机,在设置中找到显示器项 3.选中“加速3D图形” 4.在监视器中,选中 指定监视器设置,使用任意分辨率 5.如果没有可用分辨率,手动输入,例如 1680* ...
- UVa 572 - Oil Deposits (简单dfs)
Description GeoSurvComp地质调查公司负责探測地下石油储藏. GeoSurvComp如今在一块矩形区域探測石油.并把这个大区域分成了非常多小块.他们通过专业设备.来分析每一个小块中 ...
- 【SDOI 2010】 古代猪文
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1951 [算法] 欧拉定理+中国剩余定理 + lucas定理 [代码] #includ ...
- EOJ 2844 排序去重
有 n 个 1 到 1000 之间的整数 (1≤n≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉.然后再按照指定的排序方式把这些数排序. Input 第 1 行为字母 A 或 D,A ...
- Java实现一个简单的网络爬虫
Java实现一个简单的网络爬虫 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWri ...
- jbox如果弹不出,放在body里
body> <form id="form1" runat="server"> <script type="text/javas ...
- Web-数据库-mysql篇
DDL创造 create 修改 alter 删除 dorp DML插入 insert 删除 delete 更新 updateDQLselect from where MySQL与JDBC 一.用 ...
- vue 返回上一页在原来的位置
http://www.jb51.net/article/118592.htm http://blog.csdn.net/qq_26598303/article/details/51189235 htt ...
- aspnet_regiis加密文件提示路径中具有非法字符
加密结果受当前目录影响,不知道是不是哪里操作错误,mark. Web.config文件位置:E:\Web\Surgery 加密成功,上图命令最后有个".",表示web.conf ...
- eclipse离线安装pydev
首先,下载去http://pydev.org/下载Python的Eclipse插件PyDev. 目前的最新版是PyDev 2.7.1.zip,将压缩文件解压出来.得到features和plugins两 ...