哈理工练习赛 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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值