当前位置:网站首页>G巴士计数(Google Kickstart2014 Round D Problem B)(DAY 89)
G巴士计数(Google Kickstart2014 Round D Problem B)(DAY 89)
2022-07-30 05:26:00 【张学恒】
1:题目
一些城市沿着一条笔直的公路建造。
这些城市从左到右编号为 1,2,3…
有 N 个 G 巴士在这条路上运行。
对于每个 G 巴士,我们知道它服务的城市范围:第 i 个 g 巴士为编号为 Ai 和 Bi 之间的城市(包含 Ai 和 Bi)提供服务。
现在给定你一个城市子集 P。
对于 P 中包含的每一座城市,我们需要找出有多少辆 G 巴士为该城市服务。
输入格式
第一行包含整数 T,表示共有 T 组测试数据。
每组数据第一行包含整数 N,表示 G 巴士的数量。
第二行包含 2N 个整数,形式为 A1 B1 A2 B2 A3 B3…AN BN,其中第 i 个 G 巴士服务于编号从 Ai 到 Bi(包括)的城市。
第三行包含整数 P,表示询问的城市数量。
接下来 P 行,每行包含一个整数 Ci,表示一个询问城市的编号。
每组数据之前隔一个空行。
输出格式
每组数据输出一个结果,每个结果占一行。
结果表示为 Case #x: y,其中 x 是组别编号(从 1 开始),y 是 P 个空格隔开的整数,其中第 i 个整数是为城市 Ci 提供服务的 G 巴士的数量。
数据范围
1≤T≤10,
1≤N≤500,
1≤Ai,Bi,Ci≤5000,
1≤P≤500
输入样例:
2
4
15 25 30 35 45 50 10 20
2
15
25
10
10 15 5 12 40 55 1 10 25 35 45 50 20 28 27 35 15 40 4 5
3
5
10
27
输出样例:
Case #1: 2 1
Case #2: 3 3 4
样例解释
在样例#1中,有四个 G 巴士。
第一个服务城市 15 到 25,第二个服务城市 30 到 35,第三个服务城市 45 到 50,第四个服务城市 10 到 20。
城市 15 由第一个和第四个 G 巴士服务,城市 25 仅由第一个 G 巴士服务,因此答案输出为 2 1。
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5010;
int n, m;
int b[N];
int main()
{
int T;
scanf("%d", &T);
for (int cases = 1; cases <= T; cases ++ )
{
memset
(b, 0, sizeof b);
scanf("%d", &n);
for (int i = 0; i < n; i ++ )
{
int l, r;
scanf("%d%d", &l, &r);
b[l] ++ , b[r + 1] -- ;
}
for (int i = 1; i < N; i ++ ) b[i] += b[i - 1];
scanf("%d", &m);
printf("Case #%d: ", cases);
while (m -- )
{
int x;
scanf("%d", &x);
printf("%d ", b[x]);
}
puts("");
}
return 0;
}
边栏推荐
猜你喜欢
![[Redis Master Cultivation Road] Jedis - the basic use of Jedis](/img/e3/0c6efd03432a01f857796f0bf648ef.png)
[Redis Master Cultivation Road] Jedis - the basic use of Jedis

The use of Conluce, an online document management system

最新版MySQL 8.0 的下载与安装(详细教程)

是时候不得不学英语了,技多不压身,给自己多条路

即刻报名|前沿技术探索:如何让 Spark 更强劲、更灵活

JVM 类加载机制 超详细学习笔记(三)

postman 请求 post 调用 传 复合 json数据

ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program

pyinstaller打包程序所遇问题记录

Hexagon_V65_Programmers_Reference_Manual (10)
随机推荐
RadonDB MySQL on K8s 2.1.2 发布!
Record of problems encountered by the pyinstaller packager
Concurrent Programming Review
Seata异常:endpoint format should like ip:port
Participate in open source, let programmers regain their blood and passion
JVM之GC 调优基础知识(一)
go language study notes 4
DLL说明(1)
leetcode刷题
go版本升级
Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
It's time to have to learn English, give yourself multiple paths
MySQL kills 10 questions, how many questions can you stick to?
并发编程复习
为Bitbucket 和 Sourcetree 设置SSL认证
从字节码角度带你彻底理解i++与++i
腾讯面试居然跟我扯了半小时的CountDownLatch
JVM 内存结构 超详细学习笔记(一)
ThinkPHP high imitation blue play cloud network disk system source code / docking easy payment system program