当前位置:网站首页>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;
}
边栏推荐
- Internet (software) company project management software research report
- 1475. 商品折扣后的最终价格
- mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
- JVM之GC 调优基础知识(一)
- 腾讯面试居然跟我扯了半小时的CountDownLatch
- 视野 | KeyDB:为 Web 应用而生的高性能 Redis 分支
- 给小白的 PG 容器化部署教程(下)
- mysql 中 in 的用法
- curl (7) Failed connect to localhost8080; Connection refused
- 给小白的 PostgreSQL 容器化部署教程(上)
猜你喜欢
是时候不得不学英语了,技多不压身,给自己多条路
ThinkPHP高仿蓝奏云网盘系统源码/对接易支付系统程序
I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
翻译 | Kubernetes 将改变数据库的管理方式
[Redis Master Cultivation Road] Jedis - the basic use of Jedis
Docker-compose安装mysql
Hexagon_V65_Programmers_Reference_Manual (14)
Hexagon_V65_Programmers_Reference_Manual (11)
mysql cannot connect remotely Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10060 "Unknown error")
随机推荐
Programmers care guide, give yourself a chance to make the occasional relaxation of body and mind
C language implements highly secure game archives and reads files
工具 | 常用 PostgreSQL 预防数据丢失方案
期末作业C#实现学生宿舍管理系统
是时候不得不学英语了,技多不压身,给自己多条路
为Bitbucket 和 Sourcetree 设置SSL认证
Hexagon_V65_Programmers_Reference_Manual (14)
即刻报名|前沿技术探索:如何让 Spark 更强劲、更灵活
2022 Pengcheng Cup web
Path dependence: the poor hard science to counter attack breakthrough
丑陋的程序员
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
leetcode刷题
【LeetCode】Day107-除自身以外数组的乘积
坪山区关于开展2022年度科技创新专项资金申报工作的通知
How MySQL to prepare SQL pretreatment (solve the query IN SQL pretreatment can only query out the problem of a record)
Record of problems encountered by the pyinstaller packager
I went to meet some successful people worth tens of millions on May 1st, and I have some new ideas and inspirations
开源之夏 2022 重磅来袭!欢迎报名 RadonDB 社区项目!
MySQL夺命10问,你能坚持到第几问?