hdoj5124lines【贪心 or 离散化】
来源:互联网 发布:药品网络经营许可证 编辑:程序博客网 时间:2024/06/05 00:28
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1364 Accepted Submission(s): 567
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 integerN(1≤N≤105) ,indicating the number of lines.
Next N lines contains two integersXi and Yi(1≤Xi≤Yi≤109) ,describing a line.
Each test case begins with an integer
Next N lines contains two integers
Output
For each case, output an integer means how many lines cover A.
Sample Input
251 2 2 22 43 45 100051 12 23 34 45 5
Sample Output
31
Source
BestCoder Round #20
可以用离散化做但离散化还不知道怎么做此题也可以用贪心做
贪心思路是把一条线段拆成两个点后排序,那么此时当前位置如果遇到一个起点,那么被覆盖的线段数要+1,遇到终点就是一条线段完结了被覆盖的数量-1,找出过程中的最大值即可。
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;const int maxn=100010;int s[maxn];int e[maxn];bool cmp(int a,int b){ return a<b;}int MAX(int a,int b){ return a>b?a:b;}int main(){ int t,i,j,k,n; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;++i){ scanf("%d%d",&s[i],&e[i]); } sort(s,s+n,cmp); sort(e,e+n,cmp); int ans=0,temp=0,x=0,y=0; while(x<n){ if(s[x]<=e[y]){ temp++;x++; } else { temp--;y++; } ans=MAX(ans,temp); } printf("%d\n",ans); } return 0;}
0 0
- hdoj5124lines【贪心 or 离散化】
- hihoCoder1079 离散化 优先队列+贪心
- ZOJ 3790 Consecutive Blocks【离散化】【贪心】
- NOIP模拟题[贪心][离散化][LIS]
- POJ(2761)Feed the dogs (树状数组+离散化+贪心)
- ural 1987. Nested Segments【离散化+贪心+线段树】
- POJ 3666 Making the Grade DP + 离散化 + 贪心
- POJ 3666 Making the Grade 【DP + 离散化 + 贪心 】
- HDU 5303 delicious apples(贪心+离散化)好题
- [hdu 4417 Super Mario] 主席树+离散化 OR 分块
- ACM ArabellaCPC 2015 E题.二分or离散化
- SPOJ - WMELON(离散化+暴力or离散化+线段树)【待完善】
- 贪心 ? OR DP?
- SPOJ - POSTERS(离散+暴力or离散+线段树)【待完善】
- hdu 5493 Queue 2015合肥网络赛 树状数组 二分 离散化 贪心
- CF#310-E - Case of Chocolate-(set+贪心)/(线段树+离散化)/(隐式线段树)
- [NOIP模拟题][贪心][坐标离散化][最长上升序列][二分查找]
- NOIP模拟题 2016.11.5 [贪心] [坐标离散化] [循环序列LIS]
- 【Android架构Telephony篇】之数据业务(二)
- MySQL触发器
- Linux词汇
- 从phpMyAdmin批量导入Excel内容到MySQL
- spring配置数据源
- hdoj5124lines【贪心 or 离散化】
- ios开发-前言基础篇C语言
- 以“结果是否成功”为判断标准过于表面,不如结合“过程是否科学”+“客观条件是否达到”
- 如何检查内存泄露问题
- muduo库阅读(3)——基本类型之阻塞队列
- 汇编程序-更灵活的定位内存地址方法
- c语言 时间详解
- 《C专家编程》笔记三:数组和指针实参所对应的形式参数
- iOS开发-前言篇C-函数