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 ...
随机推荐
- luogu2518 [HAOI2010] 计数
题目大意 给出一个数字$n$,求满足下列条件的数$x$的个数: $x<n$ 对于来自于$x$十进制各个数位上的非零数字,它们的种类与个数都与$n$的相同. 思路 入手点 设$n$有$t$位数字, ...
- Camera-hal参数调整
路径: vendor/mediatek/proproetary/custom/mt6735/hal/D1/imgsensor/对应的SENSOR目录 .../D1/flashlight/flash_t ...
- 0x51 线性DP
数据结构没什么好写的..分块和整体二分还有点分学得很懂..果然我还是比较适合这些东西 poj2279 奇怪题,我的想法就是五维记录最边上的一斜排,会M,结果的的确确是锻炼思维的,正解并不是DP2333 ...
- 杂项-事务:OLTP(联机事务处理过程)
ylbtech-杂项-事务:OLTP(联机事务处理过程) On-Line Transaction Processing联机事务处理过程(OLTP) 也称为面向交易的处理过程,其基本特征是前台接收的用户 ...
- php 判断过去离现在几年的函数
function gettime($worktime){ $time=time(); $amount=date("Y",$time)-date("Y",strt ...
- php word转pdf
我们知道,PHP语言的合理运用可以帮助我们实现导出Word文档的功能.今天我们将为大家介绍PHP处理Word转PDF的相关实现方法. PHP关键字this指向当前对象指针 PHP self关键字指向类 ...
- HTML不熟悉方法总结
1. onblur 属性在元素失去焦点时触发. 2. onfocus 属性在元素获得焦点时触发. 3.addEventlistener 事件监听 4.focus() 方法用于给予该元素焦点.这样用 ...
- JAVA 中for-each循环使用方法
for each循环还是第一次见,“java SE 5.0增加了一种功能很强的循环结构,可以用来一次处理数组中的每个元素(其他类型的元素集合亦可)而不必为指定下标值而分心”. 这种增强的for eac ...
- Solr.NET快速入门(七)【覆盖默认映射器,NHibernate集成】
覆盖默认映射器 默认情况下,SolrNet使用属性映射Solr字段. 但是,您可能需要使用另一个映射程序. 替换默认映射器取决于您如何设置库: 内置容器 如果使用默认的内置容器,可以在调用Startu ...
- shopping car 1.0
#!/usr/bin/env python# -*- coding: utf-8 -*-# @File : 20180510001.py# @Author: Anthony.waa# @Date : ...