Lyft Level 5 Challenge 2018-Final Round(Open Div.2) B. Taxi drivers and Lyft
http://codeforces.com/contest/1075/problem/B
Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.
Lyft has become so popular so that it is now used by all mm taxi drivers in the city, who every day transport the rest of the city residents — nnriders.
Each resident (including taxi drivers) of Palo-Alto lives in its unique location (there is no such pair of residents that their coordinates are the same).
The Lyft system is very clever: when a rider calls a taxi, his call does not go to all taxi drivers, but only to the one that is the closest to that person. If there are multiple ones with the same distance, then to taxi driver with a smaller coordinate is selected.
But one morning the taxi drivers wondered: how many riders are there that would call the given taxi driver if they were the first to order a taxi on that day? In other words, you need to find for each taxi driver ii the number aiai — the number of riders that would call the ii-th taxi driver when all drivers and riders are at their home?
The taxi driver can neither transport himself nor other taxi drivers.
The first line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) — number of riders and taxi drivers.
The second line contains n+mn+m integers x1,x2,…,xn+mx1,x2,…,xn+m (1≤x1<x2<…<xn+m≤1091≤x1<x2<…<xn+m≤109), where xixi is the coordinate where the ii-th resident lives.
The third line contains n+mn+m integers t1,t2,…,tn+mt1,t2,…,tn+m (0≤ti≤10≤ti≤1). If ti=1ti=1, then the ii-th resident is a taxi driver, otherwise ti=0ti=0.
It is guaranteed that the number of ii such that ti=1ti=1 is equal to mm.
Print mm integers a1,a2,…,ama1,a2,…,am, where aiai is the answer for the ii-th taxi driver. The taxi driver has the number ii if among all the taxi drivers he lives in the ii-th smallest coordinate (see examples for better understanding).
3 1
1 2 3 10
0 0 1 0
3
3 2
2 3 4 5 6
1 0 0 0 1
2 1
1 4
2 4 6 10 15
1 1 1 1 0
0 0 0 1
代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 300010;
int n, m;
long long pos[maxn], dir[maxn];
int cnt1 = 0, cnt = 0; struct Node{
long long dis;
long long num;
}car[maxn]; int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m + n; i ++)
cin >> pos[i];
for(int i = 1; i <= n + m; i ++) {
cin >> dir[i];
if(dir[i] == 1) {
cnt1 ++;
car[cnt1].dis = pos[i];
}
} for(int i = 1; i <= n + m; i ++) {
if(m == 1) {
printf("%d\n", n + m - 1);
return 0;
}
if(pos[i] < car[1].dis)
car[1].num ++;
else if(pos[i] > car[cnt1].dis)
car[cnt1].num = car[cnt1].num + 1; else if(dir[i] == 1)
cnt ++;
else if(pos[i] * 2 > car[cnt].dis + car[cnt + 1].dis)
car[cnt + 1].num ++;
else car[cnt].num ++;
} for(int i = 1; i <= cnt1; i ++) {
cout << car[i].num;
printf("%s", i != cnt1 ? " " : "\n");
}
return 0;
}
Lyft Level 5 Challenge 2018-Final Round(Open Div.2) B. Taxi drivers and Lyft的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
B. Taxi drivers and Lyft time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)
A. The King's Race 签. #include <bits/stdc++.h> using namespace std; #define ll long long ll n, ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)---ABC
A---The King's Race http://codeforces.com/contest/1075/problem/A 题意: 一个人在\((1,1)\), 一个人在\((n,n)\), 现 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) C. The Tower is Going Home(思维+双指针)
https://codeforces.com/contest/1075/problem/C 题意 一个宽为1e9*1e9的矩阵中的左下角,放置一个车(车可以移动到同一行或同一列),放置一些墙,竖的占据 ...
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) A. The King's Race
http://codeforces.com/contest/1075/problem/A On a chessboard with a width of nn and a height of nn, ...
- Lyft Level 5 Challenge 2018 - Final Round Div. 1没翻车记
夜晚使人着迷.没有猝死非常感动. A:显然对于水平线段,只有横坐标的左端点为1的时候才可能对答案产生影响:对于竖直直线,如果要删一定是删去一段前缀.枚举竖直直线删到哪一条,记一下需要删几条水平线段就可 ...
- [Lyft Level 5 Challenge 2018 - Elimination Round][Codeforces 1033D. Divisors]
题目链接:1033D - Divisors 题目大意:给定\(n\)个数\(a_i\),每个数的约数个数为3到5个,求\(\prod_{i=1}^{n}a_i\)的约数个数.其中\(1 \leq n ...
- Lyft Level 5 Challenge 2018 - Elimination Round
A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...
随机推荐
- 2018.6.22 Java试题测试结果
如何从有数字规律的网址抓取网页并保存在当前目录?假设网址为 http://test/0.xml,其中这个数字可以递增到100. for((i=0;i<100;++i));do wget http ...
- Python监控日志中经常访问的ip
一.需求:每分钟检查一次日志文件,如果这一分钟内同一个ip请求次数超过200次,加入黑名单 1.日志文件中,每一行的格式为:XXX.XXX.XXX.XXX - - [04/Jun/2017:05:25 ...
- javaweb基础(29)_EL表达式
一.EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数 ...
- Luogu [P2814] 家谱
题目链接 这个题不难,但是有点小小坑. 首先并查集肯定能看出来. 然后字符串的话,一开始我想用 hash 来处理,但想了想,离散化不好搞,人也太多了,一不小心就hash重了,还是算了. 然后就想到了S ...
- 使用Xcode过程中遇到的问题
前言:记录一下使用Xcode过程中遇到的问题 1.关于开发者的Team的问题,是选用自己的个人Team还是选用公司的付费的Team(本机环境:Xcode9 + iPad :iOS11.0.3) 问题: ...
- java 实现猜数字游戏 随机给定一个数字,猜大小直到正确
package com.swift; import java.util.Random; import java.util.Scanner; public class GuessBigSmall { p ...
- Oracle10g安装过程中的Configuration Assistant配置失败的问题。
前几天安装Oracle的时候碰到了一个小问题,是在最后配置的时候,出现失败提示如下 失败提示:一些 Configuration Assistant 失败.强烈建议您此时重试这些 Configurati ...
- Solr7部署报错:java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z
错误信息: Servlet.service() for servlet [default] in context with path [/solr] threw exception [Filter e ...
- MySQL - FIND_IN_SET 函数使用方法
SELECT * FROM xxxTableName x WHERE FIND_IN_SET(x.id, '1,2,3,4,5,6,7,8'); 如上查询,意为:xxxTableName 表中 x ...
- Python_深浅拷贝
深浅拷贝 ‘copy’和'='的区别:copy会开辟一个新的空间,而‘=’不会. 浅copy只会copy第一层,再里边的就进行共享了. 需要记住的是copy之后记住的是内存寻址地址,而浅copy时如果 ...