lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1350    Accepted Submission(s): 558

Problem Description
John
has several lines. The lines are covered on the X axis. Let A is a
point which is covered by the most lines. John wants to know how many
lines cover A.
 
Input
The first line contains a single integer T(1≤T≤100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
 
Output
For each case, output an integer means how many lines cover A.
 
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
 
Sample Output
3
1
 
给你n条线段(点也算线段),让你找出被覆盖次数最多的线段的覆盖次数。
直接从左往右跑,线段起点加一过了减一。。。
官方题解:
我们可以将一条线段[xi,yi]分为两个端点xi和(yi)+1,
在xi时该点会新加入一条线段,同样的,在(yi)+1时该点会减少一条线段,
因此对于2n个端点进行排序,令xi为价值1,yi为价值-1,问题转化成了最大区间和,
因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案,另外的,
这题可以用离散化后线段树来做。复杂度为排序的复杂度即nlgn,
另外如果用第一种做法数组应是2n,而不是n,由于各种非确定性因素我在小数据就已
经设了n=10W的点。

题解:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+;
pair<int,int>pa[MAXN<<];
int main(){
int T,N;
scanf("%d",&T);
while(T--){int a,b;
scanf("%d",&N);
for(int i=;i<N;i++){
scanf("%d%d",&a,&b);
pa[i<<]=make_pair(a,);
pa[i<<|]=make_pair(b+,-);
}
sort(pa,pa+N*);
int ans=,cnt=;
for(int i=;i<*N;i++)
cnt+=pa[i].second,ans=max(ans,cnt);
printf("%d\n",ans);
}
return ;
}

lines(最大区间和)的更多相关文章

  1. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  2. CF444C. DZY Loves Colors[线段树 区间]

    C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  4. 【线段树区间合并】HDU1540-Tunnel Warfare

    一.题目 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  5. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  6. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  7. hdu3437 划分树 区间内小于第K大的值得和

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  8. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  9. HDU 1698 Just a Hook(线段树/区间更新)

    题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS     Memory Limit: 32768 K Description In the g ...

随机推荐

  1. 使用 system.io.filesysteminfo 来查找文件。

    如何快速搜索你想找到文件呢.大家知道Windows系统自带了搜索,很方便,下面介绍自己编写的也可以达到同样的效果.注意.有些文件的访问需要更高的权限.这里暂且去掉那些文件目录的搜索.不然会出现erro ...

  2. SQL Server索引进阶:第六级,标签

    原文地址: Stairway to SQL Server Indexes: Level 6,Bookmarks 本文是SQL Server索引进阶系列(Stairway to SQL Server I ...

  3. 在Sharepoint中批量删除大量条目

    在Sharepoint开发中可能需要一次删除成百上千条记录,这时候如果轮询SPList.Items并直接调用该对象的删除方法来删除的话性能极差,会叫你崩溃. 下面介绍一个快速删除大量数据的方法: us ...

  4. ASP.NET -- repeater控件的使用

    转载自网络-原网址[http://blog.csdn.net/haitaodoit/article/details/7021214] repeater绑定数据: protected void Page ...

  5. poj 3243 Clever Y 高次方程

    1 Accepted 8508K 579MS C++ 2237B/** hash的强大,,还是高次方程,不过要求n不一定是素数 **/ #include <iostream> #inclu ...

  6. Page Cache, the Affair Between Memory and Files

    Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O ...

  7. Aptana jQuery自动提示

    参考 http://www.ghugo.com/aptana-studio-3-jquery-autocomplete/ 对于第一种方案 是每个项目都能生效的  不过有时候网络不好时就无法顺利获取提示 ...

  8. S70卡

    产品名称:Mifare 4K(S70)卡 芯片类型:Philips Mifare 1 S70(MOA2) 存储容量:32Kbit,32个分区,每分区两组密码   工作频率:13.56 MHz   通讯 ...

  9. 无法启动此程序,因为计算机中丢失QtCore4.dll。尝试重新安装该程序以解决此问题(在系统里添加3个路径)

    解决方法: 计算机-属性-高级系统设置-高级-环境变量-系统变量-Path 添加 E:\Qt\4.8.5\bin; E:\Qt\4.8.5\qmake; E:\mingw\bin 重启计算机 http ...

  10. AssetManager中的路径参数不能包含"assets/"

    String path = “music/bg.mp3”: //正确的参数 //String path = “assets/music/bg.mp3”: //错误的参数 //String path = ...