hdu 4325 Flowers(区间离散化)
2015-11-18 15:25
337 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4325
Total Submission(s): 2633 Accepted Submission(s): 1290
[align=left]Problem Description[/align]
As is known to all, the blooming time and duration varies between different kinds of flowers. Now there is a garden planted full of flowers. The gardener wants to know how many flowers will bloom in the garden in a specific time. But there are too many flowers in the garden, so he wants you to help him.
[align=left]Input[/align]
The first line contains a single integer t (1 <= t <= 10), the number of test cases.
For each case, the first line contains two integer N and M, where N (1 <= N <= 10^5) is the number of flowers, and M (1 <= M <= 10^5) is the query times.
In the next N lines, each line contains two integer Si and Ti (1 <= Si <= Ti <= 10^9), means i-th flower will be blooming at time [Si, Ti].
In the next M lines, each line contains an integer Ti, means the time of i-th query.
[align=left]Output[/align]
For each case, output the case number as shown and then print M lines. Each line contains an integer, meaning the number of blooming flowers.
Sample outputs are available for more details.
[align=left]Sample Input[/align]
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
[align=left]Sample Output[/align]
Case #1:
0
Case #2:
1
2
1
题目大意:n种花,每种花的花期为[s,t],m次查询,每次查询问ti时刻有多少种花开
数据范围过大,无法直接开数组,那么就要用到离散化处理
方法类似hdu 5124
Flowers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2633 Accepted Submission(s): 1290
[align=left]Problem Description[/align]
As is known to all, the blooming time and duration varies between different kinds of flowers. Now there is a garden planted full of flowers. The gardener wants to know how many flowers will bloom in the garden in a specific time. But there are too many flowers in the garden, so he wants you to help him.
[align=left]Input[/align]
The first line contains a single integer t (1 <= t <= 10), the number of test cases.
For each case, the first line contains two integer N and M, where N (1 <= N <= 10^5) is the number of flowers, and M (1 <= M <= 10^5) is the query times.
In the next N lines, each line contains two integer Si and Ti (1 <= Si <= Ti <= 10^9), means i-th flower will be blooming at time [Si, Ti].
In the next M lines, each line contains an integer Ti, means the time of i-th query.
[align=left]Output[/align]
For each case, output the case number as shown and then print M lines. Each line contains an integer, meaning the number of blooming flowers.
Sample outputs are available for more details.
[align=left]Sample Input[/align]
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
[align=left]Sample Output[/align]
Case #1:
0
Case #2:
1
2
1
题目大意:n种花,每种花的花期为[s,t],m次查询,每次查询问ti时刻有多少种花开
数据范围过大,无法直接开数组,那么就要用到离散化处理
方法类似hdu 5124
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; typedef long long ll; const int N = 2000010; const int INF = 0x3f3f3f3f; int c[2 * N], a , b , used , d ; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int t, n, m, f = 0; int p, q, k, e; scanf("%d", &t); while(t--) { f++; k = 0; memset(used, 0, sizeof(used)); scanf("%d%d", &n, &m); for(int i = 0 ; i < n ; i++) { scanf("%d%d", &p, &q); a[i] = p; b[i] = q; c[k++] = p; c[k++] = p - 1;/***///这里为嘛,个人认为是防止查询的数比q要小 c[k++] = q; c[k++] = q + 1;/***/ } qsort(c, k, sizeof(c[0]), cmp); k = unique (c, c + k)- c;//去重 int x, y, maxn = -INF; for(int i = 0 ; i < n ; i++) { x = lower_bound(c, c + k, a[i]) - c; y = lower_bound(c, c + k, b[i]) - c; used[x]++; used[y + 1]--; maxn = max(maxn, y + 1); } for(int i = 0 ; i < maxn ; i++) used[i + 1] += used[i]; printf("Case #%d:\n", f); while(m--) { scanf("%d", &e); int s = lower_bound(c, c + k, e) - c; printf("%d\n", used[s]); } } return 0; }
相关文章推荐
- 第五次作业
- gcc 编译错误 Value too large for defined data type
- Java中区别.toString() ,(String) 和 valueOf()方法
- SSL 之根证书
- 【Twitter Storm系列】flume-ng+Kafka+Storm+HDFS 实时系统搭建
- 非常好的SQL格式化工具SQL Pretty Printer
- ORA-12899: 列 "RC"."MM_PACKAGE"."PACKAGE_DESC" 的值太大 (实际值: 1262, 最大值: 1024)
- jQuery中的.bind()、.live()和.delegate()之间区别分析
- Visio中如何画面积一样的形状
- 深入浅出设计模式——概述
- iOS 页面之间的跳转
- css定位机制
- 链接数据库的问题
- web -- CSS3
- DataBase First创建数据库
- 解决php的It is not safe to rely on the system’s timezone settings的问题
- 黑马程序员——Java基础——继承之多态(三)
- 将Centos的yum源更换为国内的阿里云源
- 关于java中的迭代器实现层次
- 判断浏览器对css和html的支持