[思路题] hdu 5124 lines
来源:互联网 发布:sql存储过程实例 编辑:程序博客网 时间:2024/06/01 13:12
题意:
给n个区间 [x,y],问被最多覆盖的点,被覆盖了多少次。
思路:
一个很巧妙的方法。好像原来有接触过。
就是如果给你[1,3]就used[1]++,used[4]--。
然后从左到又过一遍出现的点 依次累加每次加的时候取最大值。
然后这题需要用到map离散化。
代码:
#include"cstdlib"#include"cstdio"#include"cstring"#include"cmath"#include"queue"#include"algorithm"#include"iostream"#include"map"#include"stack"#include"vector"#define ll __int64#define inf -999999999999999999LLusing namespace std;int a[123456],b[123456];int main(){ int t; cin>>t; while(t--) { int cnt=1; int n; scanf("%d",&n); memset(a,0,sizeof(a)); map<int,int>mp; while(n--) { int x,y; scanf("%d%d",&x,&y); y++; if(!mp[x]) { b[cnt]=x; mp[x]=cnt++; } if(!mp[y]) { b[cnt]=y; mp[y]=cnt++; } a[mp[x]]++; a[mp[y]]--; } sort(b+1,b+1+cnt); int sum=0,ans=0; for(int i=1;i<cnt;i++) { sum+=a[mp[b[i]]]; ans=max(sum,ans); } printf("%d\n",ans); } return 0;}
0 0
- [思路题] hdu 5124 lines
- 【瞎搞】HDU 5124 lines
- HDU 5124 lines
- HDU 5124 lines
- HDU 5124 lines
- hdu 5124——lines
- hdu 5124 lines(贪心)
- hdu 5124 lines(离散化)
- hdu 5124 lines(Bestcoder Round #20)
- HDU 5124 lines 最多区间覆盖
- 哈理工练习赛 HDU 5124 lines
- hdu 5124 lines(树状数组)
- 5124 lines
- HDU-5031-Lines(DFS)
- hdu 5031 Lines 爆搜
- hdu 5031 Lines
- HDU 4970 思路题
- HDU 5301 思路题
- 黑马程序员----[20150428][面向对象5]
- C++、Java和Matlab不同语言关于 y=(++x)+(++x);结果不同的问题
- [G+smo]THB spline
- java面向对象之类和对象
- 大白鼠第一章例题6
- [思路题] hdu 5124 lines
- 利用国内镜像源下载、编译Android源码
- Dagger 依赖注释框架
- UISearchBar去除背景颜色
- 编程之美2015初赛A
- UcloudClient
- Hibernate多对多关联映射
- uva656(bfs)
- Java 基础 第五天