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. memcached配置 (初级)以及测试

    一.memcached安装 memcached依赖 $ sudo apt-get install libevent-dev   安装memcached服务 $ sudo apt-get install ...

  2. strongswan

    StrongSwan is an open source IPsec-based VPN Solution. It supports both the IKEv1 and IKEv2 key exch ...

  3. eclipse自动生成.apt_generated、factory path

  4. phpstorm 7.1 注册码

    phpstorm 7.1 注册码 EMBRACE ===== LICENSE BEGIN =====97393-12042010000004TIOFWznalqlK"vkzc2ilc8uub ...

  5. BURG For Ubuntu 14.04 Trusty

    sudo add-apt-repository ppa:n-muench/burg sudo apt-get updatesudo apt-get install burg burg-themes D ...

  6. Python与Go快速排序

    #!/usr/bin/env python # -*- coding: utf-8 -*- # 快速排序 # 时间复杂度 O(n lgn)-- O(n^2) def quick_sort(array) ...

  7. JSONArray的初始化的形式

    1 转义字符形式 [    {        \"ID\": \"1900036295\",        \"DEPT\": \" ...

  8. C++ 基类指针,子类指针,多态

    基类指针和子类指针之间相互赋值(1)将子类指针赋值给基类指针时,不需要进行强制类型转换,C++编译器将自动进行类型转换.因为子类对象也是一个基类对象. (2)将基类指针赋值给子类指针时,需要进行强制类 ...

  9. javascript的构造函数和实例对象、prototype和__proto__的区别,原型对象及构造器的理解

    一.前言 我们先通过代码来分别打印出实例对象.构造函数,以及修改了原型对象的构造函数,通过对比内部结构来看看他们之间的区别. //定义构造函数 function Person(name, age){ ...

  10. unity平行光太亮?物体发白?可能你使用了2个或多个平行光

    unity平行光太亮?物体发白?可能你使用了2个或多个平行光 今天做项目时就遇到了这个问题,光亮得让物体发白 发现加载的场景 里面有个 平行光,删了就好了 要是感觉还是太亮,就把主平行光的Intens ...