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. 接口自动化(三)--读取json文件中的数据

    上篇讲到实际的请求数据放置在json文件内,这一部分记述一下python读取json文件的实现. 代码如下(代码做了简化,根据需要调优:可做一些容错处理): 1 import json 2 3 cla ...

  2. django-model的元类Meta

    Meta类存在model类里面 模型元选项 文档有更多Meta类的配置属性: English:https://docs.djangoproject.com/en/1.11/ref/models/opt ...

  3. cmd变量,参数,for循环,

    @echo offrem  *****************************************************rem  Create By Q_rui CopryRight@_ ...

  4. Ubuntu 安装VNC

    ubuntu:.安装x11vnc sudo apt-get install x11vnc .设置密码 x11vnc -storepasswd .启动x11vnc(每次windows远程控制,都需要启动 ...

  5. UnityEngine.SerializeField & System.Serializable

    [UnityEngine.SerializeField] Force Unity to serialize a private field. 强制Unity序列化一个私有变量. You will al ...

  6. java多线程通信方式之一:wait/notify

    java多线程之间的通信方式有多种: 1.wait(),notify(),notifyAll()方法;2.join()方法;3.通过volatile共享内存的方式进行线程通信的;4.interrupt ...

  7. Python next() 函数

    Python next() 函数  Python 内置函数 描述 next() 返回迭代器的下一个项目. 语法 next 语法: next(iterator[, default]) 参数说明: ite ...

  8. Python dict() 函数

    Python dict() 函数  Python 内置函数 描述 dict() 函数用于创建一个字典. 语法 dict 语法: class dict(**kwarg) class dict(mappi ...

  9. ICG游戏:斐波那契博弈

    描述: 有一堆个数为n(n>=2)的石子,游戏双方轮流取石子,规则如下: 1)先手不能在第一次把所有的石子取完,至少取1颗: 2)之后每次可以取的石子数至少为1,至多为对手刚取的石子数的2倍: ...

  10. CloudStack 4.1快照测试

    目前4.1只支持存储快照,4.2能支持内快照 1. 选中实例 2. 查看实例卷 3. 创建快照 4. 通过快照创建模板 5. 查看通过快照创建的模板 6. 通过快照创建模板生成的实例 7. 自动定制创 ...