HDOJ 5124 lines 【线段树 & 离散化】
来源:互联网 发布:图像处理区域填充算法 编辑:程序博客网 时间:2024/05/16 07:24
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1347 Accepted Submission(s): 556
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
恩,题目大意就是说,每组测试数据中的每组数据表示X轴上的一段线段,然后一定存在一个点,覆盖它的线段最多,问的就是最多的线段条数。由于数据较大,需要离散化。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#define maxn 100100using namespace std;int a[maxn],b[maxn];int rec[maxn<<1];struct lnode{ int l,r,c,m;};lnode node[maxn<<2];int maxi(int a,int b){ return a>b?a:b;}void pushup(int o){ node[o].m=maxi(node[o<<1].m,node[o<<1|1].m);}void build(int o,int l,int r){ node[o].l=l; node[o].r=r; node[o].m=0; node[o].c=0; if(l==r) return ; int mid=(l+r)>>1; build(o<<1,l,mid); build(o<<1|1,mid+1,r);}void pushdown(int o){ if(node[o].c) { node[o<<1].m+=node[o].c; node[o<<1|1].m+=node[o].c; node[o<<1].c+=node[o].c; node[o<<1|1].c+=node[o].c; node[o].c=0; }}void update(int o,int l,int r){ if(node[o].l==l&&node[o].r==r) { node[o].m++; node[o].c++; return ; } pushdown(o); int mid=(node[o].l+node[o].r)>>1; if(r<=mid) update(o<<1,l,r); else if(l>mid) update(o<<1|1,l,r); else { update(o<<1,l,mid); update(o<<1|1,mid+1,r); } pushup(o);}int bsearch(int l,int r,int x){ while(l<=r) { int mid=(l+r)>>1; if(rec[mid]==x) return mid; if(rec[mid]>x) r=mid-1; else l=mid+1; }}int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); int j=1; for(int i=0;i<n;++i) { scanf("%d%d",&a[i],&b[i]); rec[j++]=a[i]; rec[j++]=b[i]; } sort(rec+1,rec+j); int m=2; for(int k=2;k<j;++k) { if(rec[k]!=rec[k-1]) rec[m++]=rec[k]; } build(1,1,m); for(int i=0;i<n;++i) { int l=bsearch(1,m,a[i]); int r=bsearch(1,m,b[i]); update(1,l,r); } printf("%d\n",node[1].m); } return 0;}
0 0
- HDOJ 5124 lines 【线段树 & 离散化】
- hdoj 5124 lines 【离散化 + 线段树】
- hdu 5124 lines (线段树+离散化)
- UESTC 1501 - Defense Lines 离散化+线段树优化DP
- 【HDOJ】 Picture (离散化+线段树)
- hdu 5124 lines(离散化)
- [线段树+离散化+单点查询] HDOJ - 4325 Flowers
- HDOJ 2492 Ping pong 线段树+离散化
- HDOJ 题目4325 Flowers(线段树+离散化)
- HDOJ 题目2836 Traversal(线段树,离散化,DP)
- 线段树+离散化
- 离散化 + 线段树
- 线段树离散化
- 线段树离散化
- hdoj 5124 lines【】
- hdoj 5124lines
- HDU 5124 lines 最大区间重叠点(离散化)
- POJ题目 1151|| HDOJ 题目1542Atlantis(线段树+离散化+扫描线)
- 【转】ubuntu下pppoe后网络图标(无线网络)消失的解决办法
- CodeForces 567E President and Roads(最短路 + 双联通分量)
- CSS学习笔记之<!important>
- hdu--4435--charge-station+贪心
- jquery ajax 不能正常调用success的问题
- HDOJ 5124 lines 【线段树 & 离散化】
- Ubuntu14.04 LTS更新源
- windows快捷键
- 测试csdn博客能否在移动端显示
- SystemC分析(1)-基本数据类型的实现
- hdu 1.3.2 排名
- IOS毛玻璃效果
- MFC进度条控件CProgressCtrl实现进度滚动效果
- 数据挖掘的基本过程