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

题意:给你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;
}

  

lines的更多相关文章

  1. extracting lines bases a list using awk

    extracting lines bases a list using awk awk 'NR==FNR{a[$1]=$0; next}($1 in a){print a[$1]"\n&qu ...

  2. Enum:Game of Lines(POJ 3668)

    画直线 题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条 数据量比较少,直接暴力枚举,然后放到set查找即可 #include <iostream> #include < ...

  3. 我的常用mixin 之 lines

    /** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...

  4. uva 1471 defence lines——yhx

    After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...

  5. POJ 1269 Intersecting Lines --计算几何

    题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...

  6. POJ 1269 Intersecting Lines【判断直线相交】

    题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...

  7. [CareerCup] 13.1 Print Last K Lines 打印最后K行

    13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...

  8. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  9. 简单几何(直线位置) POJ 1269 Intersecting Lines

    题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...

  10. 【POJ】1269 Intersecting Lines(计算几何基础)

    http://poj.org/problem?id=1269 我会说这种水题我手推公式+码代码用了1.5h? 还好新的一年里1A了---- #include <cstdio> #inclu ...

随机推荐

  1. Java 架构师面试题

    基础题目 Java线程的状态 进程和线程的区别,进程间如何通讯,线程间如何通讯 HashMap的数据结构是什么?如何实现的.和HashTable,ConcurrentHashMap的区别 Cookie ...

  2. gRPC编译教程

    windows平台的编译 一.编译openssl ① 安装perl(可以使用ActivePerl),执行perl Configure VC-WIN64A no-asm .在这里解释一下参数含义,VC- ...

  3. springboot2.0和Druid整合配置数据源

    1. idea使用spring 初始化工具初始化springboot项目(要选中web) 下一步,下一步 2. 在pom.xml中,引入Druid连接池依赖: <dependency> & ...

  4. Springboot2.0加载指定配置文件@PropertySource的使用

    1. 在resouces下编写待加载的配置文件 这里使用person.properties # String person.last-name=john # int person.age=112 # ...

  5. gcc数据对齐之: howto 1.

    GCC支持用__attribute__为变量.类型.函数.标签指定特殊属性.这些不是编程语言标准里的内容,而属于编译器对语言的扩展. 本文介绍其中的两个属性:aligned和packed. align ...

  6. 81. Search in Rotated Sorted Array II (JAVA)

    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...

  7. Assets.xcassets的使用

    先介绍下Asset Catalog,Asset Catalog是Xcode5引入的一个新的图片管理方式,有几个好处: 1.自动管理图片,如@1x,@2x图片,使用的时候使用Asset 名字即可 2.管 ...

  8. 015-Zabbix自动发现和自动注册

      前言 对于监控服务器越来越多的情况,如果还单独一个一个添加,那效率也太低,因此就要实现批量添加监控服务器的操作,Zabbix提供两种批量自动监控的方式: 自动发现:由服务端主动发起,Zabbix ...

  9. 牛客假日团队赛6 D 迷路的牛 (思维)

    链接:https://ac.nowcoder.com/acm/contest/993/D 来源:牛客网 迷路的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  10. tensorboard_embedding

    from tensorboardX import SummaryWriter import torchvision writer=SummaryWriter(log_dir="embeddi ...