当前位置:网站首页>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;
}
边栏推荐
- 开源之夏 2022 重磅来袭!欢迎报名 RadonDB 社区项目!
- Us to raise interest rates by 75 basis points in "technical recession"?Encryption market is recovering
- ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
- Acwing完全数
- 429. N 叉树的层序遍历(两种解法)
- IIS网站出现401未授权访问
- An old programmer's summary review of 2020, how to become more awesome in 2021
- Acwing perfect number
- RadonDB MySQL on K8s 2.1.2 发布!
- 从字节码角度带你彻底理解i++与++i
猜你喜欢

The use of Conluce, an online document management system

JVM之GC 调优工具 Arthas 实战使用(二)

Hexagon_V65_Programmers_Reference_Manual (12)

Acwing perfect number

How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)

JVM面试总结

Record of problems encountered by the pyinstaller packager

Concurrent Programming Review

pyinstaller打包程序所遇问题记录

Hexagon_V65_Programmers_Reference_Manual (10)
随机推荐
Unity踩坑记录 —— GetComponent的使用
Acwing perfect number
Path dependence: the poor hard science to counter attack breakthrough
Redis学习
ms project2010项目管理软件使用技巧总结
An old programmer's summary review of 2020, how to become more awesome in 2021
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
关于组织开展2022年广东省技术先进型服务企业认定工作的通知
RadonDB MySQL on K8s 2.1.3 发布!
L2-020 descendants of kung fu
一个老程序员的2020年总结回顾,2021年如何变的更牛逼
即刻报名|如何降低云上数据分析成本?
MySQL kills 10 questions, how many questions can you stick to?
[Verilog] HDLBits Problem Solution - Circuits/Combinational Logic
MySQL索引从入门到深入学习
I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations
【Redis高手修炼之路】Jedis——Jedis的基本使用
This article will take you through js to deal with the addition, deletion, modification and inspection of tree structure data
MySql字符串拆分实现split功能(字段分割转列、转行)
JVM之GC 调优基础知识(一)