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. JavaScript学习总结(一)——闭包、对象、函数

    一.闭包(Closure) 1.1.闭包相关的问题 请在页面中放10个div,每个div中放入字母a-j,当点击每一个div时显示索引号,如第1个div显示0,第10个显示9:方法:找到所有的div, ...

  2. Java作业 题目:16版.情人节送玫瑰花

    题目:16版.情人节送玫瑰花 题干: 1.实验要求 本实验要求:以情人节送花为业务背景,体验自定义异常以及异常处理机制. 1-1. 业务说明: 1-1.1. 本实验以情人节送花为业务背景,女方提出送花 ...

  3. 01: jenkins简介与安装

    jenkins参考博文:https://www.w3cschool.cn/jenkins/jenkins-173a28n4.html Jenkins中文官网:http://www.jenkins.or ...

  4. .net core 调用webservice

    原文:.net core 调用webservice 1.点击core项目添加链接的服务 2.键入对应的webservice地址,下载对应的代理服务 4.由于.net core  代理类只支持异步方法  ...

  5. cobbler装机系统部署

    1.cobbler安装 [root@linux-node1 ~]# cp /etc/cobbler/settings{,.ori} # 备份 # server,Cobbler服务器的IP. sed - ...

  6. 对mysql进行快照复制

    Myself> flush tables with read lock; 之后开始创建快照 [root@server0 mysql]# lvcreate -L 100M -s -n dbback ...

  7. 001-SaltStack入门篇(一)之SaltStack部署

    早期运维工作中用过稍微复杂的Puppet,下面介绍下更为简单实用的Saltstack自动化运维的使用. Saltstack知多少Saltstack是一种全新的基础设施管理方式,是一个服务器基础架构集中 ...

  8. SpringBootMVC01——A simple SpringBootMVC Sample

    不带数据库的SpringBootMVC案例 1.创建一个SpringBoot项目,添加thymeleaf,webstarter 2.目录层级 3.启动器代码 package com.littlepag ...

  9. canvas在高倍屏下变模糊的处理办法

    因为canvas不是矢量图,而是像图片一样是位图模式的.如果不做Retina屏适配的话,例如二倍屏,浏览器就会以2个像素点的宽度来渲染一个像素,该canvas在Retina屏幕下相当于占据了2倍的空间 ...

  10. 负载均衡(四)Nginx负载均衡策略

    一.Nginx的作用 1.反向代理 代理:转发请求的服务器,分代理和反向代理.代理一般指的是我们使用的DNS,反向代理是放在服务端的大家通常用Nginx来解决.实际应用中,由于服务端处于一个中心位置, ...