HDU 5124 lines 最大区间重叠点(离散化)
2014-12-28 22:03
417 查看
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 887 Accepted Submission(s): 403
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≤10
5
)
,indicating
the number of lines.
Next N lines contains two integers X
i
and Y
i
(1≤X
i
≤Y
i
≤10
9
)
,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[code]/* HDU 5124 最大区间重叠点(离散化) 我们可以将一条线段 [xi,yi]分为两个端点xi和(yi)+1,在xi时该点会新加入一条线段, 同样的,在 (yi)+1时该点会减少一条线段,因此对于2n个端点进行排序, 令xi为价值1,yi为价值-1,问题转化成了最大区间和,因为1一定在-1之前, 因此问题变成最大前缀和,我们寻找最大值就是答案 5 1 2 2 2 2 4 3 4 1 1 2 1 2 1 3 -1 3 -1 3 1 5 -1 5 -1 为3 */ #include<iostream> #include<stdio.h> #include<algorithm> #include<vector> using namespace std; vector< pair<int,int> > v; int main() { int t,n,i,x,max,ans; scanf("%d",&t); while(t--) { v.clear(); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&x); v.push_back(make_pair(x,1)); scanf("%d",&x); v.push_back(make_pair(x+1,-1)); } sort(v.begin(),v.end()); ans=0; max=0; for(i=0;i<v.size();i++) { ans+=v[i].second; if(ans>max) max=ans; } printf("%d\n",max); } return 0; }
[/code]
相关文章推荐
- hdu 5124 lines (线段树+离散化)
- [HDU 2883]kebab[最大流][区间离散化]
- HDU 5124 lines 最多区间覆盖
- hdu 5124 lines(离散化)
- 【HDU - 5124】 lines 【树状数组+离散化】
- hdu 5124(区间更新+单点求值+离散化)
- HDU 1867 KMP 求最大尾部重叠
- hdu 2795 Billboard【线段树,区间求最大值,点更新在区间操作中进行】
- HDU 1754 I Hate It 线段树区间求最大
- hdu I hate it 区间最大值 线段树
- HDU 1540 / POJ 2892 Tunnel Warfare (单点更新,区间合并,求包含某点的最大连续个数)
- Hdu 2883 最大流 区间 判满流
- Hdu 2795 线段树 区间最大值的位置.cpp
- 找最大的重叠区间
- HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )
- HDU 2236 矩阵不同行列寻找 最小最大数的差值 最小 二分匹配+二分枚举区间
- HDU 1050 Moving Tables (贪心 区间最大叠加数)
- hdu--1754 线段树区间求最大值
- hdu 1754 (区间最大线段树基础题)
- 单调队列的一个应用——求解连续区间最大值(HDU Max Sum of Max-K-sub-sequence)