当前位置:网站首页>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;
}
边栏推荐
- postman 请求 post 调用 传 复合 json数据
- 839. Simulated heap
- 报错:npm ERR code EPERM
- MySQL - Function and Constraint Commands
- [GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry
- IDEA的database使用教程(使用mysql数据库)
- G巴士计数(Google Kickstart2014 Round D Problem B)(DAY 89)
- 【Koltin Flow(一)】五种创建flow的方式
- Participate in open source, let programmers regain their blood and passion
- MySQL索引从入门到深入学习
猜你喜欢
随机推荐
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
"Hou Lang" programmer version, a speech dedicated to a new generation of programmers, He Bing's "Hou Lang" speech imitation show
排列数字(DAY90)dfs
108. 将有序数组转换为二叉搜索树
留念 · 大学时代最后的系统设计图
Within the SQL connection table (link connections, left or right, cross connection, full outer join)
MySql string splitting realizes the split function (field splitting, column switching, row switching)
爬虫数据是如何收集和整理的?
MySQL(3)
The difference between asyncawait and promise
从字节码角度带你彻底理解i++与++i
MySQL kills 10 questions, how many questions can you stick to?
面试题 17.13. 恢复空格(字典树)
PyCharm usage tutorial (more detailed, picture + text)
从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
navicat无法连接mysql超详细处理方法
[GLib] 什么是GType
cookie和session区别
Redis基础学习
How is crawler data collected and organized?