题目链接: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. [译]ES6箭头函数和它的作用域

    原文来自我的前端博客: http://www.hacke2.cn/arrow-functions-and-their-scope/ 在ES6很多很棒的新特性中, 箭头函数 (或者大箭头函数)就是其中值 ...

  2. Cocos2D-X 学习笔记

    1. 3.4final控制台创建项目后,安卓编译会失败,必须手动把cocos/平台/andorid/java/src目录里的文件复制到安卓项目的src文件夹即可 2. 安卓的文件目录与win的略有不同 ...

  3. 控制器View的生命周期及相关函数是什么?你在开发中是如何用的?

    * 1.首先判断控制器是否有视图,如果没有就调用loadView方法创建:通过storyboard或者代码: * 2.随后调用viewDidLoad,可以进行下一步的初始化操作:只会被调用一次: * ...

  4. 素数的线性筛 && 欧拉函数

    O(n) 筛选素数 #include<bits/stdc++.h> using namespace std; const int M = 1e6 + 10 ; int mindiv[M] ...

  5. tcl实现http请求

    package require "http" proc errLog args { puts $args } proc SendHttp args { global token s ...

  6. MySQL编译安装

    1.准备工作 其官方站点为http://www.mysql.com/ 为了避免发生端口冲突.程序冲突现象.建议先查询MySQL软件的安装情况,确认没有使用以RPM方式安装的mysql-server.m ...

  7. 类加载器ClassLoader之jar包隔离

    小引子 最近做了一个根据同一模块的不同jar版本做同时测试的工具,感觉挺有意思,特此记录. 类加载器(ClassLoader)是啥? 把类加载阶段中的"通过一个类的全限定名(博主注:绝对路径 ...

  8. HDU 5228

    #include<stdio.h> #include<string.h> *]; int main(){ int t; scanf("%d",&t) ...

  9. Maven编译项目报错:某些类找不到符号

      遇到Maven在编译项目源码时候出现找不到符号错误,主要归结为以下几个问题: 1. 可能项目编码格式不统一. 2. 可能项目编码使用的JDK版本不统一. 项目可能是当前项目也可能是继承的父项目,还 ...

  10. [codevs1141]数列

    [codevs1141]数列 试题描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12 ...