hdu5124 lines (输入输出挂写的)
来源:互联网 发布:淘宝手机充值漏洞 编辑:程序博客网 时间:2024/05/18 02:44
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
John has several lines. The lines are covered on the X axs. 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≤105),indicating the number of lines.
Next N lines contains two integers x and y(1≤x≤y≤109),describing a line.
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
线段
题目描述:
约翰有一些线段。这些线在X轴上。有一点A被多条线段覆盖,约翰想知道最多有多少线段覆盖了A点。(Tip A点为X轴上任意一点)。
输入
第一行有一个整数T,(1<=t<=100) ,代表着有几组数据。每一组数据开始于一个数字N,(1<=N<=10^5),代表着有几条线段。
接下来的N行每行有两个整数x,y,代表着线段的起点和终点。
输出
对于每组样例,输出一个整数有多少线段覆盖了A点。
解题思路(官方题解):
将一条线段[x,y]分为两个端点x和(y)+1,在x时该点会新加入一条线段,同样的,在(y)+1时该点会减少一条线段,因此对于2n个端点进行排序,令x为价值1,y为价值-1,问题转化成了最大区间和,因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案,另外的,这题可以用离散化后线段树来做。复杂度为排序的复杂度即nlgn,另外如果用第一种做法数组应是2n,而不是n。
代码 (输入输出流外挂):
/* 整个世界也填满不了十八岁男孩子的雄心和梦 *//* By---宇 */#include <queue>#include <stack>#include <math.h>#include <vector>#include <limits.h>#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <functional>#define N 100010#define LL long long#define mem(a) memset(a,0,sizeof(a));#define mem_1(a) memset(a,-1,sizeof(a));using namespace std;typedef struct{ int x,y;} D;D a[N*2+10];bool cmp(D a,D b){ if(a.x!=b.x) return a.x < b.x; return a.y > b.y;}int Scan() //输入外挂{ int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}void Out(int a) //输出外挂{ if(a>123487499) Out(a/10); putchar(a%10+'0');}int main(){ int T,i,j,n,x,y; T = Scan(); scanf("%d",&T); while(T--) { //scanf("%d",&n); n = Scan(); int cnt = 1; for(i=1; i<=n; i++) { x = Scan(); y = Scan(); a[cnt].x = x; a[cnt++].y = 1; a[cnt].x = y; a[cnt++].y = -1; } sort(a+1,a+cnt,cmp); int ans = 0; int tmp = 0; for(i=1; i<cnt; i++) { tmp+=a[i].y; ans = max(ans,tmp); } Out(ans); putchar('\n'); } return 0;}
最后说一下 输入输出外挂能比scanf快,读入最慢的就是cin .
cin 1781MS;
输入输出外挂 656 MS;
scanf 828 MS
- hdu5124 lines (输入输出挂写的)
- hdu5124——lines
- HDU5124 lines(贪心)
- HDU5124 lines(离散)
- HDU5124
- Java 的文件(读 写)输入输出
- 输入输出函数的应用--写日志
- lines
- java-Java 的文件(读 写)输入输出
- C++写的简单扫雷程序,输入输出为黑框
- 各种各样的输入输出挂 mmdns~
- 给textbox的lines赋值
- APPEND LINES OF 的用法
- 线段树离散化hdu5124
- [500lines]500行代码写web server
- 输入输出挂
- 输入输出挂
- 输入输出挂
- linux 定时运行命令脚本---crontab
- 第13周项目4-数组的排序之体验选择排序
- GAC--全局程序集缓存和SN.EXE工具
- 关于NodeJs为什么要用mongoose操作mongodb
- linux JSP 链接Mysql数据库
- hdu5124 lines (输入输出挂写的)
- 泛型算法_快速排序源码
- JFreeChart 学习示例
- mac系统升级到了10.10.但是eclipse中运行不识别真机了
- 把程序集安装到全局程序集缓存中的步骤
- [leetcode]String to Integer (atoi)
- To find sum of two numbers without using any operator. Only use of printf() is allowed.
- Android:给图片加边框
- poj 2698