哈理工练习赛 HDU 5124 lines
问题 H: lines
时间限制: 3 Sec 内存限制: 128 MB提交: 37 解决: 6
[提交][提交状态][论坛] [Edit] [TestData]
题目描述
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.
输入
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≤10^5),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤10^9),describing a line.
输出
For each case, output an integer means how many lines cover A.
样例输入
251 2 2 22 43 45 100051 12 23 34 45 5
样例输出
31 其实不用树状数组 或者线段树 照样也能做!!!!离散化是必然的。很简单。。很巧妙~
/*=============================================================================
#
# Author: liangshu - cbam
#
# QQ : 756029571
#
# School : 哈尔滨理工大学
#
# Last modified: 2015-11-29 21:45
#
# Filename: H.cpp
#
# Description:
# The people who are crazy enough to think they can change the world, are the ones who do !
=============================================================================*/
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int INF = 100003;
int c[INF], co;
int dic[INF][2], h[INF];
struct Node{
int x, num;
bool friend operator < (Node a, Node b){
return a.x < b.x;
}
}node[INF * 2];
int main()
{
int t;scanf("%d", &t);
while(t--){
memset(h, 0, sizeof(h));
int n;scanf("%d", &n);
for(int i = 1; i <= n; i++){
int x, y;
scanf("%d%d", &x, &y);
node[2 * i - 1].x = x;
node[2 * i - 1].num = i;
node[2 * i].x = y;
node[2 * i].num = -1 * i;
}
sort(node + 1, node + 2 * n + 1);
memset(dic, 0, sizeof(dic));
co = 1;
dic[abs(node[1].num)][node[1].num > 0 ? 0 : 1] = co;
for(int i = 2; i <= 2 * n; i++){
if(node[i].x == node[i - 1].x){
if(node[i].num > 0){
dic[node[i].num][0] = co;
}
else{
dic[-1 * node[i].num][1] = co;
}
continue;
}
if(node[i].num > 0){
dic[node[i].num][0] = ++co;
}
else{
dic[-1 * node[i].num][1] = ++co;
}
}
for(int i = 1; i <= n; i++){
h[dic[i][0]] += 1;
h[dic[i][1] + 1] += -1;
}
int tmp = 0, M = -1;
for(int i = 1; i <= co; i++){
if((tmp += h[i]) > M){
M = tmp;
}
}
printf("%d\n", M);
}
return 0;
}

浙公网安备 33010602011771号