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. P5596 洛谷月赛 题 题解

    因为a>=0,b>=0,所以y^2-x^2>=0,所以y>x,因为都是自然数设y=x+k,化简得x=b-k^2/2*k-a;可知x仅当b-k^2%2*k-a==0且b-k^2与 ...

  2. shell with hadoop

    shell 命令操作 hadoop 之前多少提及过,这里做个总结. shell with hdfs 基本命令 bin/hadoop fs 大于下面的命令 bin/hdfs dfs dfs 是 fs 的 ...

  3. Centos7 用gogs搭建git仓库

    0.安装步骤 先安装依赖,然后创建数据库,创建git用户,安装Gogs软件,设置启动,访问web界面进行配置 一.Gogs依赖环境 安装Gogs之前需要配置相应的依赖环境,官网介绍的依赖环境如下: 数 ...

  4. [wpf]wpf full screen.

    void window_KeyDown(object sender,KeyEventArgs e) { if(e.Key == Key.F11) { Window.ResizeMode = Resiz ...

  5. 一分钟理解sku和spu

    SPU SPU = Standard Product Unit (标准化产品单位) SPU是商品信息聚合的最小单位,是一组可复用.易检索的标准化信息的集合,该集合描述了一个产品的特性.通俗点讲,属性值 ...

  6. 【转】golang 交叉编译

    问题 golang如何在一个平台编译另外一个平台可以执行的文件.比如在mac上编译Windows和linux可以执行的文件.那么我们的问题就设定成:如何在mac上编译64位linux的可执行文件. 解 ...

  7. 修改jar包package目录结构操作方法

    开发中会遇到用第三方的jar包,有时候会出现不同的jar包,包名一致的情况,这就会引发运行时异常,找不到相应的jar包. 这种问题时常困扰我们很长时间.下面提出一种解决办法,例如gson.jar. 1 ...

  8. phpstudy mysql数据连接不上(#1130)解决办法

    问题:无论输什么密码,都显示#1130,找半天在终于在百度知道找到了,其他帖子都是水贴,暂时不知道为什么要这么加,反正加了重置服务就好了,重新打开phpMyAdmin 输入默认密码root既可 解决办 ...

  9. ajax跨域jsonp —— javascript

    目录 jsonp是什么 jsonp原理 原生js使用jsonp jquery使用jsonp jsonp是什么 jsonp作用:解决跨域问题 为什么有跨域问题? “同源策略限制了从同一个源加载的文档或脚 ...

  10. 关于ARM PC值

    PC值(Program Counter). ARM采用流水线来提高CPU的利用效率, 对于三级流水线, 一条汇编指令的执行包括 取值,  译码, 执行三个阶段. 当MOV指令的取指动作完毕后, 进入M ...