题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5124
lines
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2046 Accepted Submission(s): 892
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 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
题目大意:
给你n个区间,求这些区间覆盖的最多的点,能够覆盖几次
思路:
运用离散化的思想,将这些点排序后,进行差分区间,不需要实际的进行数据的离散化
This is the code
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1e9+7
#define LL long long
#define ULL unsigned long long //1844674407370955161
#define INT_INF 0x7f7f7f7f //2139062143
#define LL_INF 0x7f7f7f7f7f7f7f7f //9187201950435737471
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
pair<int,int> v[200005];
int main()
{int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);n=n*2;for(int i=0;i<n;++i)//离散化加差分区间{int x;scanf("%d",&v[i].first);v[i].second=1;scanf("%d",&v[++i].first);v[i].first++;v[i].second=-1;}sort(v,v+n);//pair默认第一个元素升序的排列int sum=0;int ans=0;for(int i=0;i<n;++i){sum+=v[i].second;ans=max(ans,sum);}printf("%d\n",ans);}return 0;
}