题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124

题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段的左端点和右端点。设 A 表示最多线段覆盖的点(当然这个 A 可以有多个啦,但这个无关紧要)。现在需要求的是 A 被多少条线段覆盖。

我是不会做啦.......一开始还看不懂题目= =

以下是按照题解做的,

  题解中的最大区间和,实际上就是求最大连续子序列的和。

(1)版本1   906 MS

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; #define x first
#define y second const int N = 2e5 + ;
pair<int, int> p[N]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int t, n;
while (scanf("%d", &t) != EOF)
{
while (t--)
{
scanf("%d", &n);
int a, b, cnt = ;
for (int i = ; i < n; i++)
{
scanf("%d%d", &a, &b);
p[cnt++] = make_pair(a, );
p[cnt++] = make_pair(b+, -);
}
sort(p, p+cnt);
int ans = , sum = ;
for (int i = ; i < cnt; i++)
{
sum += p[i].y;
if (sum > ans)
ans = sum;
if (sum < )
sum = ;
}
printf("%d\n", ans);
}
}
return ;
}

(2) 版本2  921 MS

for (int i =; i < cnt; i++)
{

sum += p[i].y;
if
(sum > ans)
ans = sum;
if
(sum <)
sum =;
} 改成这样:

  for (int i = 0; i < cnt; i++)
  {
    sum += p[i].y;
    ans = max(ans, sum);
  }

BestCoder20 1002.lines (hdu 5124) 解题报告的更多相关文章

  1. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  2. BestCoder15 1002.Instruction(hdu 5083) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...

  3. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  4. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  5. BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...

  6. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

  7. BestCoder12 1002.Help him(hdu 5059) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  8. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...

  9. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

随机推荐

  1. hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律

    http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...

  2. Python学习手册(1入门知识-数据类型)

    UNIX env查找技巧 在一些UNIX系统上,可以用这样一种方法避免硬编码Python解释器的路径,在文件的特定的第一行注释中写上这样一句话. #! usr/bin/env/ python...sc ...

  3. 结果集(result set)解释与用法

    解释: 引用自wiki: An SQL result set is a set of rows from a database, as well as metadata about the query ...

  4. CRect类

    类CRect是对Windows结构RECT的封装,凡是能用RECT结构的地方都可以用CRect代替. 结构RECT表示一个矩形的位置和尺寸,其定义为: typedef struct tagRECT{ ...

  5. ConcurrentHashMap-----不安全线程hashmap-安全线程-hashtable

    JDK1.0引入了第一个关联的集合类HashTable,它是线程安全的.HashTable的所有方法都是同步的.JDK2.0引入了HashMap,它提供了一个不同步的基类和一个同步的包装器synchr ...

  6. [原] Android性能优化方法

    GPU过度绘制 打开开发者选型,"调试GPU过度绘制",蓝.绿.粉红.红,过度绘制依次加深 粉红色尽量优化,界面尽量保持蓝绿颜色 红色肯定是有问题的,不能忍受 使用Hierarch ...

  7. 一张图读懂https加密协议

    搭建CA服务器和iis启用https:http://blog.csdn.net/dier4836/article/details/7719532 一张图读懂https加密协议 https是一种加密传输 ...

  8. int long 等基础类型在不同平台的大小

    转自http://www.cnblogs.com/yishuiliunian/archive/2011/03/18/1988244.html 上次腾讯面试,问我int和long分别几个字节,结果被鄙视 ...

  9. iOS企业级开发初级课程-表视图(13集)

    首先了解了表视图的组成.表视图类的构成.表视图的分类以及表视图的两个重要协议(委托协议和数据源协议),对表视图有了一个整体上的认识.接下来我们掌握了如何实现简单表视图和分节表视图,以及表视图中索引.搜 ...

  10. iOS开发——源代码管理——svn 命令行下常用的几个命令

    1.将文件checkout到本地目录    svn checkout path(path是服务器上的目录)    例如:svn checkout svn://192.168.1.1/pro/domai ...