当前位置:网站首页>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;
}
边栏推荐
- 容器化|在 S3 备份恢复 RadonDB MySQL 集群数据
- WeChat payment and payment callback
- 涂鸦Wi-Fi&BLE SoC开发幻彩灯带
- RadonDB MySQL on K8s 2.1.4 发布!
- [Vitis] Code implementation of ZCU102 development board PS-side control PL-side reset
- 最新版MySQL 8.0 的下载与安装(详细教程)
- 光明区关于促进科技创新的若干措施(征求意见稿)
- I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations
- MySql字符串拆分实现split功能(字段分割转列、转行)
- Acwing完全数
猜你喜欢

Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering

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

力扣05-替换空格——字符串问题

暴力递归到动态规划 05 (贴纸拼词)

从想当亿万富翁到职场、创业、爱情、抑郁、学医学武,我的程序人生

分布式事务之 LCN框架的原理和使用(二)

GO language study notes one

分布式事务之 Seata框架的原理和实战使用(三)

Participate in open source, let programmers regain their blood and passion

JVM 垃圾回收 超详细学习笔记(二)
随机推荐
工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
MySql string splitting realizes the split function (field splitting, column switching, row switching)
Hexagon_V65_Programmers_Reference_Manual (11)
【Redis高手修炼之路】Jedis——Jedis的基本使用
罗湖区工匠技能领军人才奖励项目申请指南
mysql基础(4)
关于组织开展2022年广东省技术先进型服务企业认定工作的通知
力扣541-反转字符串2——双指针法
即刻报名|如何降低云上数据分析成本?
路径依赖:穷人很难逆袭突破的科学道理
Mysql8.+学习笔记
容器化|在 S3 备份恢复 RadonDB MySQL 集群数据
分布式事务之 LCN框架的原理和使用(二)
Codeforces Round #809 (Div. 2) A~D
MySQL - 函数及约束命令
Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
C语言中的基本库函数(qsort)
An old programmer's summary review of 2020, how to become more awesome in 2021
Hexagon_V65_Programmers_Reference_Manual (12)
(Hexagon_V65_Programmers_Reference_Manual(13)