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

lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1362    Accepted Submission(s): 566

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
 
一个离散化, 我也是醉了, 怎么就搞不懂了。。。。
 
这题居然能不用离散化, 暴力水过, 还是会离散化好点, 但是这个水代码也粘贴下吧!!!
 
#include<stdio.h>
#include<string.h> #define N 1100000
#define max(a,b) (a>b?a:b) int a[N]; int main()
{
int T; scanf("%d", &T); while(T--)
{
int n, i, L, R; scanf("%d", &n);
memset(a, , sizeof(a)); for(i=; i<=n; i++)
{
scanf("%d%d", &L, &R);
a[L] ++;
a[R+] --;
} int Max = a[], sum=a[]; for(i=; i<N; i++)
{
sum += a[i];
Max = max(Max, sum);
} printf("%d\n", Max);
} return ;
}

水过代码

下面两个代码都是用了离散化, 但是其实我并不怎么懂离散化, 只懂了一点点, 继续学习吧!!!

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 201000 struct node
{
int L, R;
}a[N]; int b[N], V[N]; int main()
{
int T; scanf("%d", &T); while(T--)
{
int i, L, R, n, k=; scanf("%d", &n); memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(V, , sizeof(V)); for(i=; i<n; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
b[k++] = a[i].L;
b[k++] = a[i].R;
} sort(b, b+k); int z = unique(b, b+k)-b; for(i=; i<n; i++)
{
L = lower_bound(b, b+z, a[i].L) - b;
R = lower_bound(b, b+z, a[i].R) - b;
V[L]++;
V[R+]--;
} int sum=V[], Max = V[];
for(i=; i<N; i++)
{
sum += V[i];
Max = max(Max, sum);
} printf("%d\n", Max);
}
return ;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map> using namespace std; #define N 200005 struct node
{
int L, R;
}a[N]; int V[N], b[N]; map<int, int>dic; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int i, j, k=, n, L, R; scanf("%d", &n); memset(a, , sizeof(a));
memset(V, , sizeof(V));
memset(b, , sizeof(b)); for(i=; i<n; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
b[k++] = a[i].L;
b[k++] = a[i].R;
} sort(b, b+k);
j=;
for(i=; i<k; i++)
{
if(i==)
dic[b[i]]=j++;
else if(b[i]!=b[i-])
dic[b[i]]=j++;
} for(i=; i<n; i++)
{
L = dic[a[i].L];
R = dic[a[i].R];
V[L]++;
V[R+]--;
} int Max = V[], sum = V[]; for(i=; i<N; i++)
{
sum += V[i];
Max = max(Max, sum);
} printf("%d\n", Max);
}
return ;
}

(树状数组+离散化)lines--hdu --5124的更多相关文章

  1. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  3. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  4. HDU 4325 Flowers 树状数组+离散化

    Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...

  5. HDU 4325 Flowers(树状数组+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...

  6. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  7. HDU 5256 - 序列变换 ,树状数组+离散化 ,二分法

    Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少 ...

  8. HDU 5792 World is Exploding(树状数组+离散化)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...

  9. hdu 5877 Weak Pair dfs序+树状数组+离散化

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Prob ...

随机推荐

  1. IE7下面踩得坑

    bug1.position:fixed:z-index:99; 出现了z-index:2的层级跑到他上面了, 为什么?会出现这问题??? 检查: 1你的固定定位的容器是不是被其他容器包裹,你包裹得容器 ...

  2. Liunx Pwd

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  3. redis 数据类型为list命令整理以及示例

    常用来制作队列,当然lpush+rpop也能做栈 #将RPUSH RPUSHX LPUSH LPUSHX一并介绍(具体介绍RPUSH和RPUSHX,因为其实就是插入的方向的区别) RPUSH key ...

  4. ZBlog你选择PHP还是ASP?

    最近趁着空闲玩了一下zblog,对于很多第一次接触zblog的博主大多都会问zblog是PHP好还是ASP好?我们应该如何选择?其实,对于这个问题我也不是很懂,我个人比较倾向于PHP.今天我就整理一下 ...

  5. Delphi、Lazarus保留字、关键字详解

    Delphi.Lazarus保留字.关键字详解 来自橙子,万一的博客以及其他地方 保留字:变量等标识符可以再使用: 关键字:有特定含义,不能再次重新定义: 修饰字:类似保留字的功能,也就是说可以重用 ...

  6. UI设计教程:关于版式设计

    版式设计是视觉传达的重要手段之一,版式设计,即把有限的视觉元素在版面页进行有效的视觉组合,最优化地传达信息的同时,去影响受众,使受众产生视觉上的美感. 版式设计基本流程  在进行版式设计时,设计作品的 ...

  7. 判断某个字符串里面是否包含caoyang 这个字符串?

    $string = 'Lorem ipsum dolor sit amet'; $preg = '/caoyang/'; $status = preg_match($preg, $string,$ma ...

  8. Data Dictionary 数据字典

    数据字典是一种通用的程序设计方法.可以认为,不论什么程序,都是为了处理一定的主体,这里的主体可能是人员.商品(超子).网页.接口.数据库表.甚至需求分析等等.当主体有很多的属性,每种属性有很多的取值, ...

  9. [Jmeter] 在jenkins上通过命令行运行时,针对单个listener生成的chart报告,并通过邮件发送出来

    We need to use cmdrunner-2.0.jar Firstly, download cmdrunner-2.0.jar from here:https://jmeter-plugin ...

  10. 获取JavaScript异步函数的返回值

    今天研究一个小问题: 怎么拿到JavaScript异步函数的返回值? 1.错误尝试 当年未入行时,我的最初尝试: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <s ...