(树状数组+离散化)lines--hdu --5124
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
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.
#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的更多相关文章
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- HDU 4325 Flowers 树状数组+离散化
Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...
- HDU 4325 Flowers(树状数组+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- HDU 5256 - 序列变换 ,树状数组+离散化 ,二分法
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少 ...
- HDU 5792 World is Exploding(树状数组+离散化)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...
- hdu 5877 Weak Pair dfs序+树状数组+离散化
Weak Pair Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Prob ...
随机推荐
- Android.FamousBlogs
1. cyrilmottier http://cyrilmottier.com/ http://cyrilmottier.com/about/ 2. greenrobot http://greenro ...
- Android.Study.Question
1. NullPointerException 1.1 发生该异常的原因. 1.2 解决方法有哪几种? try-catch 2. Eclipse 中 debug/run 两个模式,run 是relea ...
- Python如何管理内存?
对于Python来说,内存管理涉及所有包含Python对象和堆. Python内存管理器在内部确保对堆的管理和分配. Python内存管理器具有不同的组件,可处理各种动态存储管理方面,如共享,分段,预 ...
- 终于搞定Fastreport2.x PDF输出,相信其他版本也差不多
这个版本有powerpdf可以支持,但有bug, 经过反复摸索,终于搞定. 基本可用. 主要是中英文混合在一起,如果按中文输出,会有英文宽度也是中文的宽度了,格式变化,不可 接受. 而按英文输出,又是 ...
- CURLOPT_HEADER
curl_setopt($curl, CURLOPT_HEADER, false); true:输出请求头
- idea部署tomcat-404错误
今天在部署数据质量web工程在tomcat后,访问时报404错误,在网上搜了很多相关配置,也都是一步一步来的 Application Context 也配置好了,Artifact也添加了,就是访问不了 ...
- Two Sum LT1
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- contenteditable设置元素可编辑
需求背景 实现一个输入框,高度可以随着输入文字的增加而自动增高 有placeholder,输入为空时,显示placeholder 我们知道可以将div的contenteditable设置伪true,将 ...
- regexper-正则表达式检验
https://regexper.com 例如:输入 \s.?\w{1,3}(\d(\W)(#?\d{1..4}))
- 导入mysql报错问题
今天数据导入报错:Got a packet bigger than‘max_allowed_packet’bytes的问题 2个解决方法: 1.临时修改:mysql>set global max ...