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 ...
随机推荐
- oc10--练习
// // main.m // 练习 #import <Foundation/Foundation.h> @interface Car : NSObject { @public int w ...
- 0x56 状压DP
gan这两题怎么差不多 #include<cstdio> #include<iostream> #include<cstring> #include<cstd ...
- 怎样才是一个基本水平的java程序员?
怎样才是一个基本水平的java程序员? 熟悉常用的数据结构,包括数组,链表,树,哈希表等. 熟悉结构化编程和面向对象编程. 能够阅读UML设计图,根据UML语义进行编码 了解RDBMS和SQL的使用, ...
- 【转】寻找最好的笔记软件:海选篇 (v1.0)
原文网址:http://blog.sina.com.cn/s/blog_46dac66f01000b55.html 序言: 我见过的多数软件爱好者,无论是资深用户,还是初级用户,都有一个梦想:找到 ...
- python程序中用类变量代替global 定义全局变量
在python编程中,一般使用global 关键字来定义全局变量,但是发现 global 关键字在涉及多个文件时,好像存在问题. 比如,单个文件下用global定义使用全局变量的情况 ,看下面的代码 ...
- 一篇个人感觉比较好的lua入门的文章
原文转自www.cppprog.com,由三篇文章组成 Lua是一个嵌入式的脚本语言,它不仅可以单独使用还能与其它语言混合调用.Lua与其它脚本语言相比,其突出优势在于: 1. 可扩展性.Lua的扩 ...
- C-C语言概述
1.数据+算法=程序. 2.C语言程序是由一个或多个函数组成的,函数是由语句组成的,语句是由关键字,标识符,运算符,数据组成的:语句可分为:声明语句,赋值语句,控制语句,函数语句,空语句. 3.#in ...
- Function 构造器及其对象、方法
一.基础 Function 是一个构造器,能创建Function对象,即JavaScript中每个函数实际上都是Function 对象. 构造方法: new Function ([arg1[, ar ...
- VS Code中编写html(4) 标签的宽高颜色背景设置
1 <!+Tab键--> <!--有两个div标签时,分别设置style,有两种方法--> <div id="div1">第一个div标签:& ...
- iOS,android 常用命令
iOS 常用命令: https://blog.csdn.net/ilikekand17/article/details/81907179 https://www.jianshu.com/p/72c62 ...