Flowers

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2579    Accepted Submission(s): 1265

Problem Description
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.
 
Input
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.
 
Output
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.
 
Sample Input
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
 
Sample Output
Case #1:
0
Case #2:
1
2
1
 题解:类似颜色段那题,突发奇想,二分搞了搞,upper,lower那错了半天,想了一组数据才发现问题;
代码:
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-);
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=1e5+;
int s[MAXN],e[MAXN];
int main(){
int t,M,N,flot=;
scanf("%d",&t);
while(t--){
scanf("%d%d",&N,&M);
for(int i=;i<N;i++){
scanf("%d%d",&s[i],&e[i]);
}
sort(s,s+N);sort(e,e+N);
int q;
printf("Case #%d:\n",++flot);
// for(int i=0;i<N;i++)printf("%d ",s[i]);puts("");
// for(int i=0;i<N;i++)printf("%d ",e[i]);puts("");
while(M--){
scanf("%d",&q);
int x=upper_bound(s,s+N,q)-s;
int y=lower_bound(e,e+N,q)-e;
//printf("%d %d\n",x,y);
// if(e[y-1]==q)y--;
// if(s[x]==q)x++;
printf("%d\n",x-y);
}
}
return ;
}

Flowers(二分水过。。。)的更多相关文章

  1. Candies CodeForces - 991C(二分水题)

    就是二分暴力就好了 为什么要记下来 呵呵....emm你说为什么... 行吧 好吧 我一直以为我的二分出问题了 原来不是 依旧很帅 统计的时候求的减了多少次  然后用次数乘了mid 这样做会使那个人获 ...

  2. C - Can you solve this equation? HDU - 2199(二分水题)

    Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...

  3. Bridging signals(二分 二分+stl dp)

    欢迎参加——每周六晚的BestCoder(有米!) Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 6 ...

  4. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  5. BZOJ3613 南园满地堆轻絮 二分/贪心

    正解:贪心 解题报告: 传送门! 这题似乎是可以二分水过的,,,但数据可以加强一下就能简单把二分卡住了,或者修改下空间限制什么的反正就很容易能卡住 所以这里介绍一个优秀的贪心做法,O(n)的时间复杂度 ...

  6. pairs

    pairs http://acm.hdu.edu.cn/showproblem.php?pid=5178 Time Limit: 2000/1000 MS (Java/Others)    Memor ...

  7. AC日记——[Sdoi2010]粟粟的书架 bzoj 1926

    1926 思路: 主席树+二分水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500005 #defi ...

  8. 牛客网NOIP赛前集训营-提高组18/9/9 A-中位数

    链接:https://www.nowcoder.com/acm/contest/172/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  9. hdu5249

    这个是去年astar的题~ 标准做法主席树,然而渣渣并不会(我确实叫zhazha...), 所以,他先离线,离散化,然后树状数组+二分水过了.... 离线的目的主要是为了离散化,剩下的就和用一个树状数 ...

随机推荐

  1. 激活Windows 10 正式版

    原文 http://jingyan.baidu.com/article/27fa732684b5f646f8271ff4.html Windows 10只提供为期一年的免费升级.因此,不要无限拖延期自 ...

  2. oracle命令大全

    内容包括三大项:    1.oracle基本操作语句 2.SQLServer基本操作语句 3.各种数据库连接方法 ******************************************* ...

  3. 目前网络上大部分的网站都是由ASP或PHP开发,并且java平台的软件购买成本不适合中小企业客户,一般适用于银行、国家安全等行业领域

    目前网络上大部分的网站都是由ASP或PHP开发,并且java平台的软件购买成本不适合中小企业客户,一般适用于银行.国家安全等行业领域. 要求建设开发大型复杂的网站,但仅有一个idea,不能够提供网站详 ...

  4. BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班

    题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec  Memory Limit: 128 MB Description      ...

  5. 【Leetcode】Triangle

    给定一个由数字组成的三角形,从顶至底找出路径最小和. Given a triangle, find the minimum path sum from top to bottom. Each step ...

  6. java解析xml的几种方式

    java解析xml的几种方式 DOM DOM的全称是Document ObjectModel,也即文档对象模型.在应用程序中,基于DOM的XML分析器将一个XML文档转换成一个对象模型的集合(通常称D ...

  7. WPF与Winform的选择

    最近公司计划对ERP系统全面升级,现有的ERP是简单的bs架构系统打算改版成cs.平时如自己写一些工具,小应用都是用winform就足够.但是界面总是很难看,据了解WPF在这一方面会强一些.因为之前对 ...

  8. Raspberry 3安装docker

    SD卡制作 准备一张4GB或者以上的micro sd卡,下载系统镜像,例如raspbian-jessie-lite.img,并使用刷机工具,如Pi filler将其写入sd卡,当然也可以使用命令行的d ...

  9. Android——用户登陆及用户名和密码的保存

    Android——用户登陆及用户名和密码的保存   在之前的学习过程中已经将Android学习完了,但是在后面将近一年的时间里都没有进行过Android开发,所以对Android的所有的知识点又有点忘 ...

  10. 关于QuartusII中的文件加密

    有时候我们要把工程交接给别人,但是又不希望对方看到里面的东西.在网上查找了几位大牛的博客进行整合 来自coyoo博客 http://bbs.ednchina.com/BLOG_ARTICLE_2482 ...