HDU 4343 贪心
D - Interval query
Time Limit: 1.5 Sec
Memory Limit: 256 MB
Description
This is a very simple question. There are N intervals in number axis, and M queries just like “QUERY(a,b)” indicate asking the maximum number of the disjoint intervals between (a,b) .
Input
There are several test cases. For each test case, the first line contains two integers N, M (0<N, M<=100000) as described above. In each following N lines, there are two integers indicate two endpoints of the i-th interval. Then come M lines and each line contains two integers indicating the endpoints of the i-th query.
You can assume the left-endpoint is strictly less than the right-endpoint in each given interval and query and all these endpoints are between 0 and 1,000,000,000.
Output
For each query, you need to output the maximum number of the disjoint intervals in the asked interval in one line.
Sample Input
3 2
1 2
2 3
1 3
1 2
1 3
Sample Output
1
2
HINT
题意
给你一些区间,现在有m个查询,求出每个查询的区间内的最大的不相交区间个数
题解:
二分,比赛的时候这样写,我艹了一直超时,赛后看了qscqesze多加了一个判断,加上去结果过了,太弱了
代码:
///
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//*************************************************************** struct ss
{
int x,y;
}a[],b[];
int lll;
int rrr;
bool cmp(ss a,ss b)
{
return a.y<b.y||(a.y==b.y&&a.x>b.x);
}
int n,l,r;
int main()
{
int m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=; i<n; i++)
{
a[i].x=read();
a[i].y=read();
}
int tot=;
sort(a,a+n,cmp);
for(int i=;i<n;i++)
{
int flag=;
for(int j=i+;j<n;j++)
{
if(a[j].y>a[i].y)break;
if(a[j].x<a[i].x)continue;
flag=;
break;
}
if(!flag)b[tot++]=a[i];
}
n=tot;
for(int i=;i<=m;i++)
{
lll=read();
rrr=read();
int ans=;
l=;r=n-;
int aa=-;
while(l<=r)
{
int mid=(l+r)>>;
if(b[mid].y<=lll)
{
aa=mid;
l=mid+;
}
else r=mid-;
}
for(int i=aa+;i<n;i++)
{
if(b[i].y<=rrr)
{
if(b[i].x>=lll)ans++,lll=b[i].y;
}else break;
}
printf("%d\n",ans);
} }
return ;
}
HDU 4343 贪心的更多相关文章
- 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(贪心 + 倍增)
题目链接 2012多校5 Problem D 题意 给定$n$个区间,数字范围在$[0, 10^{9}]$之间,保证左端点严格大于右端点. 然后有$m$个询问,每个询问也为一个区间,数字范围在$[ ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
- hdu 4974 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- HDU 2307 贪心之活动安排问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 1052 贪心+dp
http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...
随机推荐
- 新浪微博客户端(13)-使用UIWebView加载OAuth授权界面
使用UIWebView加载OAuth授权界面 DJOAuthViewController.m #import "DJOAuthViewController.h" @interfac ...
- [bug]使用SharpZipLib遇到中文名称乱码问题
写在前面 业务逻辑是这样的,需要导出一个app的话题,并需要把该话题下帖子的附件导出,然后需求想修改成人员的名称.jpg的格式.所以就出现了中文乱码的问题.在本地没问题,但发布到服务器上面就出问题,每 ...
- LINUX中,Vi编辑器的几种模式及保存、退出等命令
vi编辑器有三种模式: 命令模式,编辑模式,末行模式 打开vi后首先是命令模式,用i,o,a等进入编辑模式,按esc退出编辑模式,回到命令模式. 在命令模式下输入:wq表示保存退出,:wq!强制保存退 ...
- UVa12726 one Friend at a Time (位 广搜)
题目链接:UVa12726 是个PDF,不好复制进来. 大意:有个人要追个妹子,想加妹子QQ,但是不知道谁规定的,玩QQ的人要加好友必须先要有至少k个共同好友.共有N个人玩QQ,编号为1到N,1是男主 ...
- 注意页面上的时间戳可能会成为bd快照的时间_快照不更新的原因
之前在创建内容的时候,为了提高说服力,添加了一个原始文章的地址**.com.cn/2013-08/22/content_**.htm,当时写文章是在12月份,单快照直接变成原始文章的时间戳8.22
- 多层神经网络与C++实现
BP理论部分参考:http://blog.csdn.net/itplus/article/details/11022243 参考http://www.cnblogs.com/ronny/p/ann_0 ...
- javascript return false 详解
在大多数情况下,为事件处理函数返回false,可以防止默认的事件行为.例如,默认情况下点击一个<a>元素,页面会跳转到该元素href属性指定的页. Return False 就相当于终止符 ...
- 基于网页内容数据采集 PHP开发学习笔记
jQuery数字的截取: str.toFixed(num);//小数的截取 toFixed() <script type="text/javascript"> var ...
- Javascript之十大常用原理性样例大总结
案例一:全选等 运用知识点:ondblclick=()| onclick | 寻找标签属性及判断和函数的应用
- (0,eval)('this')与eval的区别
看doT源码的时候,看到了这么一句代码: global = (function(){ return this || (0,eval)('this'); }()); global.doT = doT; ...