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) { ...
随机推荐
- Selenium关闭windows系统弹窗
Selenium关闭windows系统弹窗 背景:在使用某业务时,会弹出windows框 提示要打印某个文本,效果如下,而正常脚本执行完了后,关闭了driver,windows的弹框还是不会消失,这时 ...
- 为项目创建podfile
由于写项目 不常用到,容易忘记,记录一下 第一步:新建一个项目: 第二步:打开终端,输入 cd 第三步:把项目拖入终端,(获取项目路径) 第四步:回车,输入 pod init (生成podfile 文 ...
- flush caches
- Python中的集合set
>>> help(set) Help on class set in module __builtin__: class set(object) | set(iterable) -- ...
- c++ 中常量与变量 基本数据类型
c++中常量如何分类? 1.整数常量,所有的整数. 整数又分为 int (integer) 占用4个字节 一个字节占几个二进制位?8个二进制位,一个整型变量占32位二进制位 (内存中开辟出来的存储空间 ...
- Solr7部署报错:java.lang.NoSuchMethodError: javax.servlet.ServletInputStream.isFinished()Z
错误信息: Servlet.service() for servlet [default] in context with path [/solr] threw exception [Filter e ...
- 揭密 Vue 的双向绑定
Vue 中需要输入什么内容的时候,自然会想到使用 <input v-model="xxx" /> 的方式来实现双向绑定.下面是一个最简单的示例 剖析Vue原理& ...
- A Bug's Life(削弱版食物链)
Description Background Professor Hopper is researching the sexual behavior of a rare species of bug ...
- Java集合框架汇总
HashMap是一个最常用的Map,它根据键的HashCode值存储数据,根据键可以直接获取它的值,具有很快的访问速度,遍历时,取得数据的顺序是完全随机的.HashMap最多只允许一条记录的键为NUL ...
- 哦?原来Python 面试题是这样的,Python面试题No19
本面试题题库,由公号:非本科程序员 整理发布 第1题:是否遇到过python的模块间循环引用的问题,如何避免它? 这是代码结构设计的问题,模块依赖和类依赖 如果老是觉得碰到循环引用可能的原因有几点: ...