lines

lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1375    Accepted Submission(s): 571

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

Source

BestCoder Round #20

题意:给你n个区间覆盖x轴,问哪个点被覆盖的线段数多,是几条。

由于数据范围太大,所以离散化……

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define maxn 500008

struct node
{
    int op,num;
}P[maxn];

int cmp(node a, node b)
{
    return a.op < b.op;
}

int main()
{
    int t, n, x, y;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        int k = 0, j;

        for(int i = 0; i < n; i++)
        {
            scanf("%d%d", &x, &y);
            P[k].op = x;
            P[k++].num = 1;
            P[k].op = y+1;
            P[k++].num = -1;
        }
        sort(P, P+k, cmp);
        int cnt = 0, Max = 0;

        for(int i = 0; i < k; )
        {
            j = i;
            while(P[j].op == P[i].op && j < k)
            {
                cnt += P[j].num;
                j++;
            }

            i = j;
            Max = max(Max, cnt);
        }
        printf("%d\n", Max);
    }
    return 0;
}

  

时间: 2024-10-20 09:44:18

lines的相关文章

[BZOJ] 1614: [Usaco2007 Jan]Telephone Lines架设电话线

1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1806  Solved: 773[Submit][Status][Discuss] Description Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用. FJ的农场周围分布着N(1 <= N <= 1,000)根按1..N顺次编号的废

lines(最大区间和)

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1350    Accepted Submission(s): 558 Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which

【POJ 3668】Game of Lines

Game of Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6555   Accepted: 2439 Description Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) distinct lattice points. Dot i ha

HDU5124:lines(线段树+离散化)或(离散化思想)

http://acm.hdu.edu.cn/showproblem.php?pid=5124 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 conta

HDOJ 5031 Lines

枚举角度DFS.... Lines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 479    Accepted Submission(s): 140 Problem Description You play a game with your friend. He draws several lines on the paper wi

[POJ 1269]Intersecting Lines

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16311   Accepted: 7040 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three

[Grid Layout] Describe a grid layout using named grid lines

We can use named grid lines to describe our grid layout. Let’s see how to apply this to our grid-template-columns and grid-template-rows, and how to refer to these from our grid items. Syntax like: grid-template-columns: [left-sidebar-start] 1fr [mai

rviz学习笔记(二)——Markers: Points and Lines (C++) 点和线

一.在using_marker/src中编写点和线代码 vim ~/catkin_ws/src/using_marker/src/points_and_lines.cpp 编写代码,其中有注释 #include <ros/ros.h> #include <visualization_msgs/Marker.h> #include <cmath> int main( int argc, char** argv ) { //创建一个发布器 ros::init(argc, a

POJ1269 Intersecting Lines[线段相交 交点]

Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15145   Accepted: 6640 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three

Finding Lines

Finding Lines 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4967 概率 在听题解前毫无头绪,题解帮我打开了新世界的大门: 随机取一个点在答案直线(如果存在这个直线)上的概率是p%, 那么随机取到两个点构成的直线就是答案直线的概率是p%*p%: 也就是说,随机取到两个点构成的直线不是答案直线的概率为