HDU 5124 lines 最大区间重叠点(离散化)
来源:互联网 发布:中国文化报 知乎 编辑:程序博客网 时间:2024/05/18 00:13
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 integerN(1≤N≤105) ,indicating the number of lines.
Next N lines contains two integersXi and Yi(1≤Xi≤Yi≤109) ,describing a line.
Each test case begins with an integer
Next N lines contains two integers
Output
For each case, output an integer means how many lines cover A
Sample Input
251 2 2 22 43 45 100051 12 23 34 45 5
Sample Output
31/*HDU 5124 最大区间重叠点(离散化) 我们可以将一条线段 [xi,yi]分为两个端点xi和(yi)+1,在xi时该点会新加入一条线段,同样的,在 (yi)+1时该点会减少一条线段,因此对于2n个端点进行排序,令xi为价值1,yi为价值-1,问题转化成了最大区间和,因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案51 2 2 22 43 41 12 12 13 -13 -13 15 -15 -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;}
1 0
- HDU 5124 lines 最大区间重叠点(离散化)
- hdu 5124 lines(离散化)
- hdu 5124 lines (线段树+离散化)
- [HDU 2883]kebab[最大流][区间离散化]
- HDU 5124 lines 最多区间覆盖
- 最大重叠区间大小
- 最大不重叠区间
- 最大区间重叠.
- HDOJ 5124 lines 【线段树 & 离散化】
- hdoj 5124 lines 【离散化 + 线段树】
- Mayor's posters(区间覆盖+点离散化)
- ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和
- hdu 2883 kebab(最大流,判断满流,区间化点)
- 最大重叠点
- hdu 4325 Flowers (区间处理 离散化)
- 求最大重叠区间大小
- #HDU 4325 Flowers 【离散化、区间加减法】
- hdu 5124 lines(贪心)
- ViewGroup.removeView(View view)&ViewGroup.removeViewAt(int index)
- Oracle游标小结
- HttpServletResponse状态码对照表
- MFC(网络编程,孙鑫C++第十四讲笔记整理)
- Struts2中的struts.multipart.saveDir的配置
- HDU 5124 lines 最大区间重叠点(离散化)
- struts2的action之间互相传递动态参数
- Beaglebone Black——修改设备树文件
- leetcode:Excel Sheet Column Number
- 局部二值模式LBP-简单人脸识别(三)
- c++ 关于引用 &的进一步理解
- Java--String类的2种赋值方式
- extJS
- HDU 5150 Sum Sum Sum 素数求和