lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1350    Accepted Submission(s): 558

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 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.
 
Output
For each case, output an integer means how many lines cover A.
 
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
 
Sample Output
3
1
 
给你n条线段(点也算线段),让你找出被覆盖次数最多的线段的覆盖次数。
直接从左往右跑,线段起点加一过了减一。。。
官方题解:
我们可以将一条线段[xi,yi]分为两个端点xi和(yi)+1,
在xi时该点会新加入一条线段,同样的,在(yi)+1时该点会减少一条线段,
因此对于2n个端点进行排序,令xi为价值1,yi为价值-1,问题转化成了最大区间和,
因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案,另外的,
这题可以用离散化后线段树来做。复杂度为排序的复杂度即nlgn,
另外如果用第一种做法数组应是2n,而不是n,由于各种非确定性因素我在小数据就已
经设了n=10W的点。

题解:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+;
pair<int,int>pa[MAXN<<];
int main(){
int T,N;
scanf("%d",&T);
while(T--){int a,b;
scanf("%d",&N);
for(int i=;i<N;i++){
scanf("%d%d",&a,&b);
pa[i<<]=make_pair(a,);
pa[i<<|]=make_pair(b+,-);
}
sort(pa,pa+N*);
int ans=,cnt=;
for(int i=;i<*N;i++)
cnt+=pa[i].second,ans=max(ans,cnt);
printf("%d\n",ans);
}
return ;
}

lines(最大区间和)的更多相关文章

  1. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  2. CF444C. DZY Loves Colors[线段树 区间]

    C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  4. 【线段树区间合并】HDU1540-Tunnel Warfare

    一.题目 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

  5. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  6. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  7. hdu3437 划分树 区间内小于第K大的值得和

    Minimum Sum Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  8. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  9. HDU 1698 Just a Hook(线段树/区间更新)

    题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS     Memory Limit: 32768 K Description In the g ...

随机推荐

  1. window.open 使用方法

    window.open(url,name,features,replace); //parameters 解释: URL:需要打开的URL Name:打开URL的标题 Feature:控制窗口大小的参 ...

  2. 当前项目与当前环境的JDK版本不匹配”Bad version number in .class file“

    java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLoader.d ...

  3. unicode编码相互转换加密解密

    需求:把字符串转换成unicode编码加密. 也可以把unicode编码解密并分析出汉字字母数字字符各多少个. unicode编码 \u 后面是一个16进制编码,必要时需要进行转换. 看源码: 0 & ...

  4. maven copy 依赖jar包

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-depen ...

  5. R语言学习之主成分分析法的R实践

    主成分分析R软件实现程序(一): >d=read.table("clipboard",header=T) #从剪贴板读取数据 >sd=scale(d)  #对数据进行标 ...

  6. [LeetCode]题解(python):068-Text Justification

    题目来源: https://leetcode.com/problems/text-justification/ 题意分析: 输入一个字符串数组和一个规定长度L.将这个字符串数组的元素尽可能放到长度的L ...

  7. 我的Python成长之路---第一天---Python基础(4)---2015年12月26日(雾霾)

    五.数据运算与数据运算符 1.算术运算符 算术运算符 运算符 描述 示例 + 加法 >>> 14 - 5 9 - 减法 >>> 14 - 5 9  *  乘法 &g ...

  8. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  9. Hbuilder 常用快捷键汇总

    朋友推荐用Hbuilder编辑器,看了下Hbuilder官网和那视频,感觉牛逼哄哄的, 自己也就体验了一下,打开Hbuilder的快捷键列表,每个快捷键都体验了一下,以下展示出来的,每一个都是精华,每 ...

  10. Android Animations动画使用详解

    一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...