HDUOJ lines
来源:互联网 发布:通达oa迁移linux 编辑:程序博客网 时间:2024/06/11 20:56
/*linesTime Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 590 Accepted Submission(s): 277Problem DescriptionJohn 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. InputThe 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. OutputFor each case, output an integer means how many lines cover A. Sample Input251 2 2 22 43 45 100051 12 23 34 45 5 Sample Output31 Source BestCoder Round #20 */#include<stdio.h>#include<string.h>#include<stdlib.h>int comp(const void *a,const void *b){return *(int *)a-*(int *)b;}int a[100005],b[100005];int main(){int cases,j,i,temp_j,temp_i,p,cnt,max,n;scanf("%d",&cases);while(cases--){memset(a,-1,sizeof(a));memset(b,-1,sizeof(b));max=-1,cnt=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}qsort(a,100005,sizeof(int),comp);qsort(b,100005,sizeof(int),comp);for(j=0;;j++){if(b[j]!=-1) break;}temp_j=j;for(i=0;i<100005;i++){if(a[i]==-1) continue;if(a[i]>b[j]) { cnt--; j++; temp_j=j; break; }else{ p=1;cnt++;temp_i=i;if(cnt>max) max=cnt;while(p){if(a[++temp_i]==a[i]){break;}while(1){if(b[temp_j++]==a[i]) {cnt--;j++;temp_j=j;}else {p=0;temp_j=j;break;}}}}}printf("%d\n",max);}return 0;}//这题是一次bc的b题,下面是大仙的代码,和我的想法一样, 不过他用结构体标记左右端点,再混合排序,而我对结构体不熟悉//没想到用这个所以就用a,b数组讨论成数组的形式,思维情况比较复杂,wa了5,6次。最后还是ac了 ,时间和大仙的那个差不多,差了100ms左右。 #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct line{ int x; int flag;}L[200010];bool cmp(line a,line b){ if(a.x<b.x||(a.x==b.x&&a.flag<b.flag)) return 1; return 0;}int main(){ int _,n,all,a,b; scanf("%d",&_); //用_作为循环变量,值得学习。 while(_--){ scanf("%d",&n); all=0; for(int i=1;i<=n;i++){ scanf("%d%d",&a,&b); L[all].x=a; L[all++].flag=0; L[all].x=b; L[all++].flag=1; } sort(L,L+all,cmp); int total=0; int ma=0; for(int i=0;i<all;i++){ if(L[i].flag==0) total++; else total--; if(total>ma) ma=total; } printf("%d\n",ma); } return 0;}//大仙的ac的代码。
0 0
- HDUOJ lines
- HDUOJ
- HDUoj
- lines
- HDUOJ 2050
- HDUOJ 2018
- HDUOJ 2069
- HDUOJ 1303
- HDUOJ 2031
- HDUOJ 2047
- HDUOJ 2089
- hduoj 1708
- hduoj 2031
- hduoj 2032
- hduoj 1062
- HDUOJ 1039
- HDUOJ入门
- HDUOJ 水果
- 看到这种单例, 也是醉了
- Little Zu Chongzhi's Triangles(计算几何加贪心)
- Picture - POJ 1177 扫描线 矩阵合并的周长
- sql server2008笔记
- Ext js 动态改变表头
- HDUOJ lines
- Python学习笔记——开篇
- Android UI自定义Spinner下拉框(用popuwindow实现)
- eVC的安装
- UML基础知识
- AFNetworking源码解析<四>
- UVA - 10801 Lift Hopping 最短路
- 蓝桥杯第二次选拔E.Wooden Sticks
- Linux常用命令(四十三) - isof