题目链接: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. Java当中的内存分配以及值传递问题内存解析

    首先必须说明作为Java程序员对于内存只要有大致的了解就可以了,如果你对Java当中的某一个知识点在不需要分析内存分配过程的情况下可以掌握,那就大可不必去研究内存.如果你对知识点已经掌握,那么你应该把 ...

  2. IOS开发之----NSDictionary,JSON和XML互相转换

    本文永久地址为 http://www.cnblogs.com/ChenYilong/p/4044521.html,转载请注明出处.     -(void)test {     //XML文本范例   ...

  3. ajxa

    ajxa上传文件提交: ajxa跨域:http://www.cnblogs.com/sunxucool/p/3433992.html http://www.cnblogs.com/fsjohnhuan ...

  4. AlwaysOn可用性组功能测试(一)--AlwaysOn故障转移测试

    具体测试环境请参考: AlwaysOn可用性组测试环境安装与配置(一)--SQL群集环境搭建 AlwaysOn可用性组测试环境安装与配置(二)--AlwaysOn配置(界面与T-SQL) 一. Alw ...

  5. asp.net—缓存

    1.页面缓存 要实现页面输出缓存,只要将一条 OutputCache 指令添加到页面即可. <%@ OutputCache CacheProfile=" " NoStore= ...

  6. JAVA 笔记

    一.Java基础以及面向对象编程1.float类型的数自动转换成double类型时,可能会出现前后不相等的情况,因为有些数不能够用有限的二进制位精确表示.2.右移>>右移,左边空出位以符号 ...

  7. loadrunner-27796错误寻求解决办法

    Action.c(58): Error -27796: Failed to connect to server "www.baidu.com:80": [10048] Addres ...

  8. http之错误码

    http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型 ...

  9. js中的json

    1.什么是JSON? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 2.JSON语法是JavaScr ...

  10. iOS开发——UI基础-控制器,IBAction和IBOutlet,UIView

    第一个ios程序 @interface ViewController : UIViewController @property(nonatomic, weak)IBOutlet UILabel *la ...