当前位置:网站首页>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;
}
边栏推荐
- JVM 内存结构 超详细学习笔记(一)
- MySQL - Function and Constraint Commands
- el-table中加入el-input框和el-input-number框,实现el-table的可编辑功能
- JVM之GC 调优基础知识(一)
- 解读 Kylin 3.0.0 | 更敏捷、更高效的 OLAP 引擎
- Golang——从入门到放弃
- 力扣344-反转字符串——双指针法
- The Golden Circle Rule: Deep Thinking Methods for Successful People
- go language study notes 2
- MySQL kills 10 questions, how many questions can you stick to?
猜你喜欢

RadonDB MySQL Kubernetes 2.2.0 发布!

从字节码角度带你彻底理解异常中catch,return和finally,再也不用死记硬背了

Programmers care guide, give yourself a chance to make the occasional relaxation of body and mind

Golang go-redis cluster模式下不断创建新连接,效率下降问题解决

mysql basics (4)

go版本升级

pyinstaller打包程序所遇问题记录

腾讯面试居然跟我扯了半小时的CountDownLatch

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

并发编程复习
随机推荐
How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)
Seata异常:endpoint format should like ip:port
pytorch官网中如何选择以及后面的安装和pycharm测试步骤
Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money
翻译 | 解读首部 Kubernetes 纪录片
一个老程序员的2020年总结回顾,2021年如何变的更牛逼
mysql基础(4)
【Redis高手修炼之路】Jedis——Jedis的基本使用
Golang——从入门到放弃
程序员赚钱实操,手把手教你做付费课程,自媒体,付费文章及付费技术课赚钱
行业案例|数字化经营底座助力寿险行业转型
期末作业C#实现学生宿舍管理系统
108. 将有序数组转换为二叉搜索树
Hexagon_V65_Programmers_Reference_Manual (10)
Internet (software) company project management software research report
Participate in open source, let programmers regain their blood and passion
从字节码角度带你彻底理解异常中catch,return和finally,再也不用死记硬背了
Hexagon_V65_Programmers_Reference_Manual (11)
mysql cannot connect remotely Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060 "Unknown error")
从驱动表和被驱动表来快速理解MySQL中的内连接和外连接