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 ...
随机推荐
- VS自带WCF测试客户端简单介绍
在目前的二次开发项目中,一些信息是放在客户那里的,只给你一个服务地址,不知道具体有什么方法,每次想调用一个服务不知道能不能实现目前的需求,只能测试.写个测试程序真的划不来,占用时间不说,而且你忙了一上 ...
- Linux unzip解压文件到某个目录下面
1,例如我想解压Metinfo5.2.zip 到某一个文件夹下,执行下面的命令就可以了 sudo unzip MetInfo5.2.zip -d metinfo-bak
- Servlet的生命周期及filter,servletRequest和servletResponse
序,Web应用中,Servlet和Filter是很重要的两个概念,一定要理解透彻. 一.Servlet类 继承自HttpServlet,HttpServlet是一个抽象类,主要包含的方法有init,s ...
- TCPIP,Http,Socket的区别
网络由下往上分为 物理层.数据链路层.网络层.传输层.会话层.表示层和应用层. 通过初步的了解,我知道IP协议对应于网络层,TCP协议对应于传输层,而HTTP协议对应于应用层, 三者从本质上来说没有可 ...
- Unity 利用NGUI做屏幕分辨率适配+学习UIDraggablePanel的使用
原地址:http://blog.sina.com.cn/s/blog_697b1b8c0101g2r4.html 大家使用unity,一定有看中其跨平台的强大功能,因此也难免会遇到不同屏幕分辨率适配的 ...
- node.js模拟qq漂流瓶
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) node.js模拟简易漂流瓶,页面有扔瓶子和捡瓶子的功能,一个瓶子只能被捡到一次,阅读完就置状态位, ...
- 见招拆招:绕过WAF继续SQL注入常用方法
Web Hacker总是生存在与WAF的不断抗争之中的,厂商不断过滤,Hacker不断绕过.WAF bypass是一个永恒的话题,不少基友也总结了很多奇技怪招.那今天我在这里做个小小的扫盲吧.先来说说 ...
- Linux 日志文件utmp、wtmp、lastlog、messages
1.有关当前登录用户的信息记录在文件utmp中:==who命令 2.登录进入和退出纪录在文件wtmp中:==w命令 3.最后一次登录文件可以用lastlog命令察看: 4.messag ...
- django signal 浅析
默认的signals极其参数 (django 1.6.5) 模型的(django/db/models/signal.py): from django.dispatch import Signal cl ...
- php如何将数组保存为文件的方法? 三个方法让你快速把数组保存成为文件存储
php 缓存数组形式的变量,实际上就是将 php 将数组写入到一个文本文件或者后缀名为 .php 存储起来,使用的时候直接调用这个文件.那么如何使用 php 将数组保存为文本格式的文件呢?下面分享三种 ...