HDU 5124 lines 最多区间覆盖
来源:互联网 发布:c语言数组存储符号 编辑:程序博客网 时间:2024/05/22 14:15
点击打开链接
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 453 Accepted Submission(s): 220
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
Source
BestCoder Round #20
官方题解:
我们可以将一条线段[xi,yi] 分为两个端点xi 和(yi)+1 ,在xi 时该点会新加入一条线段,同样的,在(yi)+1 时该点会减少一条线段,因此对于2n个端点进行排序,令xi 为价值1,yi 为价值-1,问题转化成了最大区间和,因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案,另外的,这题可以用离散化后线段树来做。复杂度为排序的复杂度即nlgn ,另外如果用第一种做法数组应是2n,而不是n,由于各种非确定性因素我在小数据就已经设了n=10W的点。
//953MS1792K#include<stdio.h>#include<algorithm>using namespace std;pair<int,int>p[200007];int main(){ int t; scanf("%d",&t); while(t--) { int n,a,b; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a,&b); p[i*2]=make_pair(a,1); p[i*2+1]=make_pair(b+1,-1); } sort(p,p+2*n);//对坐标进行排序 int ans=0,maxx=0; for(int i=0;i<2*n;i++) { ans+=p[i].second; if(ans>maxx)maxx=ans; } printf("%d\n",maxx); } return 0;}
0 0
- HDU 5124 lines 最多区间覆盖
- HDU 5124 lines 最大区间重叠点(离散化)
- 找到被区间覆盖最多的点
- hdu 5124 点的最多覆盖线段数+离散化
- 【瞎搞】HDU 5124 lines
- HDU 5124 lines
- HDU 5124 lines
- HDU 5124 lines
- HDU 4293 Groups 区间覆盖 区间DP
- 线性时间求出能够覆盖的最多区间数目
- UVa 10535 - Shooter (最多区间覆盖的点 + 扫描)
- hdu 5124——lines
- [思路题] hdu 5124 lines
- hdu 5124 lines(贪心)
- hdu 5124 lines(离散化)
- 最多区间
- 区间相关问题的学习: 最多不相交区间问题,区间选点问题与区间覆盖问题
- HDU 1050 Moving Tables 【区间覆盖】
- List ( interface ) 方法 总结
- MySQL二进制日志
- 【IOS 开发】Object-C 运算符
- 【水题】 ZOJ 3838 Infusion Altar
- UITextField 使用全面解析
- HDU 5124 lines 最多区间覆盖
- 浏览器对象模型
- 博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈)
- 如何运用Xcode创建单元测试UnitTest
- 在java中使用dom4j解析xml
- ZOJ 3838 Infusion Altar(数学啊 模拟啊 这么挫的代码你见过吗?)
- js生日祝福
- linux下使用yum安装mysql
- SDUTOJ 3023 X的畅想 我人生的第一个自己AC的DP题 && 递归