当前位置:网站首页>G Bus Count (Google Kickstart2014 Round D Problem B) (DAY 89)
G Bus Count (Google Kickstart2014 Round D Problem B) (DAY 89)
2022-07-30 06:06:00 【Zhang Xueheng】
1:题目
Some cities are built along a straight road.
The cities are numbered from left to right 1,2,3…
有 N 个 G Buses run on this road.
对于每个 G 巴士,We know the city limits it serves:第 i 个 g The bus is numbered Ai 和 Bi 之间的城市(包含 Ai 和 Bi)提供服务.
Now given you a subset of cities P.
对于 P for each city included,We need to find out how many cars there are G Buses serve the city.
输入格式
第一行包含整数 T,表示共有 T 组测试数据.
每组数据第一行包含整数 N,表示 G number of buses.
第二行包含 2N 个整数,形式为 A1 B1 A2 B2 A3 B3…AN BN,其中第 i 个 G The bus service is numbered from Ai 到 Bi(包括)的城市.
第三行包含整数 P,Indicates the number of cities queried.
接下来 P 行,每行包含一个整数 Ci,Indicates the number of a query city.
A blank line precedes each set of data.
输出格式
每组数据输出一个结果,每个结果占一行.
结果表示为 Case #x: y,其中 x 是组别编号(从 1 开始),y 是 P 个空格隔开的整数,其中第 i The integers are for the city Ci 提供服务的 G number of buses.
数据范围
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 巴士.
The first service city 15 到 25,The second service city 30 到 35,The third service city 45 到 50,The fourth service city 10 到 20.
城市 15 by the first and fourth G bus service,城市 25 Only by the first one G bus service,So the answer output is 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;
}
边栏推荐
猜你喜欢

MySQL (2)

Within the SQL connection table (link connections, left or right, cross connection, full outer join)

pwn-ROP

Mysql8.+学习笔记

个人博客系统(附源码)

Redis学习

net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.

并发编程复习

MySQL 有这一篇就够(呕心狂敲37k字,只为博君一点赞!!!)
![[详解C语言]一文带你玩转数组](/img/1b/245fdc7f3711cf794175da7a93b128.png)
[详解C语言]一文带你玩转数组
随机推荐
navicat连接MySQL报错:1045 - Access denied for user ‘root‘@‘localhost‘ (using password YES)
CISP-PTE真题演示
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
如何使用FirewallD限制网络访问
PyCharm使用教程(较详细,图+文)
4461. 范围分区(Google Kickstart2022 Round C Problem B)
Within the SQL connection table (link connections, left or right, cross connection, full outer join)
Docker-compose install mysql
最新版MySQL 8.0 的下载与安装(详细教程)
MySQL kills 10 questions, how many questions can you stick to?
JVM之GC 调优基础知识(一)
MySQL 数据库基础知识(系统化一篇入门)
MySQL - Function and Constraint Commands
[Koltin Flow (2)] The end operator of the Flow operator
分布式事务之 Atomikos 原理和使用(一)
手把手教你设计一个CSDN系统
idea设置自动带参数的方法注释(有效)
Navicat new database
【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)
MYSQL-InnoDB的线程模型