MYF

HDU 5124 lines

题目链接

HDU 5124

题目类型:水题

题目来源:BestCoder Round #20

题目分析

题目大意

给出$n$条线段,输出覆盖的线段最多的点的覆盖数

解析

离散化,然后遍历各个点即可

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <iostream>
#include <deque>
#include <algorithm>
#define Memset(a,val) memset(a,val,sizeof(a))
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define rt(n) (i == n ? '\n' : ' ')
#define hi printf("Hi----------\n")
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);
#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;
#define debug2(x,y) cout<<"Debug : ---"<<x<<" , "<<y<<"---"<<endl;
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int mod=110119;
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int x[maxn],y[maxn],tmp[maxn<<1];
int c[maxn*2];
int main(){
int t;
scanf("%d",&t);
while (t--) {
Memset(c, 0);
int n;
scanf("%d",&n);
int j = 1;
for (int i=0; i<n; i++) {
scanf("%d%d",&x[i],&y[i]);
tmp[j++]=x[i];
tmp[j++]=y[i];
}
sort(tmp+1, tmp+j);
int cnt = unique(tmp+1, tmp+j)-tmp-1;
for (int i=0; i<n; i++){
x[i]=lower_bound(tmp+1, tmp+1+cnt, x[i])-tmp;
y[i]=lower_bound(tmp+1, tmp+1+cnt, y[i])-tmp;
c[x[i]]++;
c[y[i]+1]--;
}
int ans = 0;
for (int i=1; i<=cnt; i++) {
c[i]+=c[i-1];
ans = max(ans, c[i]);
}
cout<<ans<<endl;
}
}