http://acm.hdu.edu.cn/showproblem.php?pid=5124

lines

 
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≤10^5),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤10^9),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
  
这道题与hdu1556做相似先看看hdu1556
 
题目大意: n个气球涂色,从编号a开始涂直到编号b,问每个气球被涂多少次
 
将起点x和终点y标记,然后再然后再处理标记之间的数
 
数据分析:
3 1 1 1 2 1 3
气球编号                    0    1    2    3    4
 第一次                       0    1    -1   0    0
 第二次                       0    2    -1   -1   0
 第三次                       0   3    -1   -1   -1
 最终                           0    3    2     1    0   
 
hdu 1556的代码:
 
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define max(a, b)(a > b ? a : b)
#define N 100010 int c[N];
int main()
{
int n, a, b, i;
while(scanf("%d", &n), n)
{
memset(c, , sizeof(c));
for(i = ; i <= n ; i++)
{
scanf("%d%d", &a, &b);
c[a]++;
c[b + ] -= ;
}
for(i = ; i <= n ; i++)
c[i + ] += c[i];
printf("%d", c[]);
for(i = ; i <= n ; i++)
printf(" %d", c[i]);
printf("\n");
}
return ;
}

在看这道题

题目大意:给一个线段涂色,n次操作,每次操作从点x涂到y,问最后涂得最多的那个点被涂了几次

与hdu 1556 做法相同,但是Xi 、 Yi(1≤Xi≤Yi≤10^9),数组没法开,所以我们需要想个办法来处理,就是离散化

我们将xi、yi都存在一个数组c里面,然后查找出xi和yi在数组c中出现的位置,用xi、yi各自的位置来代替xi、yi,再

来用上面的方法来写

lower_bound(c, c + 2 * n , a[i]) - c 这个函数返回的值是a[i]在数组c中第一次出现的位置

upper_bound(c, c + 2 * n , a[i]) - c 这个函数返回的值是a[i]在数组c中最后一次出现的位置

代码如下:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm> using namespace std; const int N = ;
typedef long long ll; int a[N], b[N], c[N], used[N]; int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
} int main()
{
int t, n, p, q, x, y;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
memset(used, , sizeof(used));
for(int i = ; i < n ; i++)
{
scanf("%d%d", &p, &q);
a[i] = p;
b[i] = q;
}
for(int i = ; i < n ; i++)
{
c[i] = a[i];
c[i + n] = b[i];
}
qsort(c, * n , sizeof(c[]), cmp);
for(int i = ; i < n ; i++)
{
x = lower_bound(c, c + * n , a[i]) - c;//这个函数用来查找a[i]在c中第一次出现的位置
y = lower_bound(c, c + * n , b[i]) - c;
used[x]++;
used[y + ]--;
}
for(int i = ; i < * n ; i++)
used[i+] += used[i];
qsort(used, * n, sizeof(used[]), cmp);
printf("%d\n", used[ * n - ]);
}
return ;
}
 
 

hud 5124 lines(思维 + 离散化)的更多相关文章

  1. hdoj 5124 lines【线段树+离散化】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题意:给你n段区间,他们有重合的点A,问你重合最多次的点A重合多少次 题解:对区间离散化后,维护 ...

  2. hdu 5124 lines

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 题意:给你n条线段,然后找出一个被最多条线段覆盖的点,输出覆盖这个点的线段的条数. 思路:可以把一条线段分 ...

  3. Anton and Lines(思维)

    Anton and Lines time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. 【扫描线】HDU 5124 lines

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 [题意] 在数轴x上,每次操作都覆盖一个区间的所有点,问被覆盖次数最多的点是覆盖了多少次 [思路] 最简单 ...

  5. (树状数组+离散化)lines--hdu --5124

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 lines Time Limit: 5000/2500 MS (Java/Others)    Memor ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...

  7. hdu 5124(区间更新+单点求值+离散化)

    lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. hdu 5792 树状数组+离散化+思维

    题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a< ...

  9. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

随机推荐

  1. django-创建表的字段属性,表关系

    表的各种属性文档:null char ..., django与之对应的文档 https://docs.djangoproject.com/en/1.11/ref/models/fields/   英文 ...

  2. linux性能调优

    1-1.0  关于ulimit linux对每个用户,系统限制其最大进程数.为提高性能,可根据设备资源情况,设置各linux用户最大进程数. [Qrui@root ~]#ulimit -a 用来显示当 ...

  3. 学python着几个要搞清楚WSGI和uWSGI区别

    1 WSGI是一种通信协议 2 uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信. 3 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器.

  4. Rhythmk 学习 Hibernate 04 - Hibernate 辅助工具 之 JBoos Tool

    1.安装JBoos Tool Help -> Install new Software 然后添加: http://download.jboss.org/jbosstools/updates/de ...

  5. maven+testng+reportng的pom设置

    在pom.xml 加入: <dependency> <groupId>org.testng</groupId> <artifactId>testng&l ...

  6. s2选择框的全选和反选jQuery

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. liunx 命令大全

    一.切换到用户 1.切换到根用户(root) su 2.切换到a用户 su a 二.建立用户,以及mysql的目录1.groupadd mysql #建立一个mysql的组2.useradd -r - ...

  8. win7 python2.7安装PIL库

    一.前言 遇到客户给了一个需求,需要拼接多个图片,上网找到一个解决方式,不过是需要安装PIL的,相信安装过这个库的应该都遇到很多问题,接下来说说怎么解决. 我的环境是: 操作系统:win10 64bi ...

  9. c语言define和typedef区别和使用

    define完全可以理解替换,typedef代表别名.听着差不多的意思,那2者区别在哪? 先来个简单例子查看基本使用. //define和typedef区别 #define DB double //替 ...

  10. mysql启动参数 skip-grant-tables

    非常有用的mysql启动参数—— --skip-grant-tables. 顾名思义,就是在启动mysql时不启动grant-tables,授权表.有什么用呢?当然是忘记管理员密码后有用. 在mysq ...