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 1 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

题意:t 组数据,每组给出 n 个区间 [xi,yi],求这些区间段所覆盖的最多的点

思路: 对于一个区间 [xi,yi],将其分为两个端点 xi、yi,在 xi 端点时该点会新加入一条新的线段,而对于 yi+1 的点,在该点时会减少一条线段,因此可以将给出的 2n 个端点进行排序,同时,令 xi 价值为 1,yi 价值为 -1,这样一来,问题就由区间覆盖转换你为了最大区间和,由于 1 一定在 -1 之前,因此问题又转换为了最大前缀和,寻找最大值即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define N 100001
#define LL long long
using namespace std;
int n;
pair<int,int> a[N*2];//由于将区间转为点,需要进行扩容
int main(){int t;scanf("%d",&t);while(t--){scanf("%d%",&n);n*=2;for(int i=1;i<=n;i++){scanf("%d",&a[i].first);//左端点xia[i].second=1;//左端点赋值i++;scanf("%d",&a[i].first);//右端点yia[i].first++;//右端点后移一位a[i].second=-1;//右端点赋值}sort(a+1,a+1+n);//默认对第一个元素升序排序int maxx=-INF;int sum=0;for(int i=1;i<=n;i++){sum+=a[i].second;//求前缀和maxx=max(maxx,sum);///记录最大值}printf("%d\n",maxx);}return 0;
}

Lines(HDU-5124)相关推荐

  1. 有源汇有上下界最大流/最小流 配题(HDU 3157)

    因为是有源汇所以设源点为 s,汇点为 t. 有源汇有上下界最大流: 连接一条 t 指向 s 的边,容量为 INF. 通过上述步骤,现在图变成了无源汇网络. 引入超级源点 S,超级汇点 T. 连接一条 ...

  2. 最大表示法--环形字符串最大字典序(HDU 5442)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 问题概述:n个字符围成一个环,请从这个环中找出字典序最大的长度为n的字符串,输出它的起始点和方向(0顺1 ...

  3. S-Nim (HDU 1536)组合博弈SG多组游戏

    S-Nim 题目链接 Problem Description Arthur and his sister Caroll have been playing a game called Nim for ...

  4. HDU2019多校第二场 1009(HDU 6599) I Love Palindrome String(回文树(自动机)+manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 解题思路: 回文自动机求每个本质不同的子串出现的次数,同时记录每个节点i代表的回文串第一次出现的 ...

  5. UVA 1471 Defense Lines (STL + 二分)

    大体题意: 给你一个长度为n(n < 2e5)的序列,你的任务是删除一个连续的子序列,使得剩下的序列中有一个长度最大的连续递增子序列.求最大序列长度? 思路: 因为要删除一个连续的子序列,所以会 ...

  6. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

  7. Ant Trip(HDU 3018)---多笔画问题

    题目链接 题目描述 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together w ...

  8. (HDU - 1847)Good Luck in CET-4 Everybody!(博弈)

    题目链接:Good Luck in CET-4 Everybody! - HDU 1847 - Virtual Judge (ppsucxtt.cn) 题目是中文的,我在这就不翻译题意了. 先说一种打 ...

  9. Dividing(HDU 1059)(多重背包_二进制优化)

    题目链接: 题意:有价值分别为1,2,3,4,5,6的marbles(大理石)若干,问是否能使这些marbles平分.[marbles总数不超过2e4(很明显这是一个大常数,所以用二进制优化来做)] ...

  10. 美素数(HDU 4548)(打表,简化时间复杂度)

    相信大家都喜欢美的东西,让我们一起来看看美素数吧. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为"美素数",如29,本身是素数,而且2+9 = 11 ...

最新文章

  1. php redis linsert,LINSERT命令_视频讲解_用法示例-redis编程词典-php中文网
  2. C++ 3 基本数据类型
  3. 树的更多相关算法-3
  4. Java 文件压缩与解压缩
  5. 如何编写testbench的总结(非常实用的总结)
  6. fullcalendar 显示的时间间隔只有四十五分钟_【体能新视点】——女子篮球运动员比赛期间的心率、血乳酸浓度和时间运动分析...
  7. Html和websocket初识
  8. 集成学习之参数调整策略
  9. GitHub Actions使用学习最全文档
  10. go excel换行符替换_微软Excel与WPS Excel哪个好玩?
  11. python美多商城项目百度网盘_美多商城项目(六)
  12. Batch Normalization(BN层)详解
  13. 几个分形的matlab实现1,基于MATLAB实现分形图形的绘制.doc
  14. 【Nodejs】用http模块写一个简单的web服务器
  15. macOS 10.13 High Sierra的新增功能,现已上市
  16. 汉诺塔在VC控制台的图形演示
  17. 拼多多稽查系统升级,现在还有3个稳定出评
  18. Wonderware-InTouch的历史趋势的历史数据导出为【Excel】表
  19. mds、mds_stores、mdworker 占用大量 cpu 和内存
  20. php判断运营商,PHP根据手机号判断运营商(详细介绍附代码)

热门文章

  1. 中国AI人才缺口500万,10本硬核技术书带你上车
  2. 造了一个 Redis 分布锁的轮子,没想到还学到这么多东西!!!
  3. 码码的土狼:架构的原则、范式及治理
  4. Jeecg-Boot 快速开发平台,前后端分离—开发工具安装
  5. 【技术文档】jeecg3.7-maven搭建环境入门 - 老版本
  6. 【JEECG技术博文】Jeecg高级查询器
  7. 利用 Win32 启动和检测 UWP App 的方法
  8. Jmeter 压测基础笔记
  9. jsp中forward与sendRedirect的区别
  10. shell脚本之函数篇