Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)
1 second
256 megabytes
standard input
standard output
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 — nn riders.
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 <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define debug(x) cout << "&&" << x << "&&" << endl;
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a, b, sizeof(a));
typedef long long ll;
const ll mod=;
const int inf = 0x3f3f3f3f;
void read() {freopen("in.txt","r",stdin);}
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head const int maxn=;
int n,m,L[maxn],R[maxn],ans[maxn],pos[maxn],dir[maxn];
int main() {
//read();
scanf("%d%d",&n,&m);
for(int i=;i<=n+m;i++) scanf("%d",&pos[i]);
for(int i=;i<=n+m;i++) scanf("%d",&dir[i]);
for(int i=;i<=n+m;i++) {//从1开始,很巧妙,预处理也很巧
if(dir[i]) L[i]=i;
else L[i]=L[i-];
}
R[n+m+]=n+m+;
for(int i=n+m;i>=;i--) {
if(dir[i]) R[i]=i;
else R[i]=R[i+];
}
for(int i=;i<=n+m;i++) {
if(!dir[i]) {//如果是乘客,并且L[i]为0即没有左司机,或右司机>n+m并且左距离大于右距离
if(!L[i]||(R[i]<=n+m&&pos[i]-pos[L[i]]>pos[R[i]]-pos[i])) ans[R[i]]++;
else ans[L[i]]++;
}
}
for(int i=;i<=n+m;i++) {
if(dir[i]) printf("%d ",ans[i]);
}
}
Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) B 1075B (思维)的更多相关文章
- Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...
- 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)
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) 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) { ...
- Lyft Level 5 Challenge 2018 - Elimination Round翻车记
打猝死场感觉非常作死. A:判一下起点和终点是否在其两侧即可. #include<iostream> #include<cstdio> #include<cmath> ...
随机推荐
- Java 的标识符
标识符: 在写代码的时候为了增强代码的阅读性会自定义很多名字,如:类名.方法名.变量名等 这种名称成为标识符 标识符命名规则: 由字母(可以是中文).数字.下划线.$ 组成,但不能以数字开头 大小写敏 ...
- DataGrid 单元格输入验证 由ValidatingEditor事件完成
private void gdv_reguline_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContai ...
- Linux 正文处理命令及tar vi 编辑器 homework
作业一: 1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/passwd /etc/group >/1.txt 2) 将用户信息数据库文件和用 ...
- HDLM命令dlnkmgr详解之四_monitor/offline/online
1. monitor 以一定的时间间隔监控hba或cha口的IO信息. 命令格式 监控hba口的IO信息: dlnkmgr monitor -hbaid HBA_ID [-intvl Interval ...
- java反射专题一
一丶Class的理解 /* * Class类是反射的源头 * 创建一个类,通过编译(javac.exe),生成对应的.class文件,之后使用java.exe加载(JVM的类加载器完成的)此.clas ...
- 删除CentOS系统自带的jdk
转自:https://www.cnblogs.com/linjiqin/archive/2013/03/23/2977377.html 在安装CentOS6.4时,系统会自动安装jdk,先把它下载掉, ...
- java代码连接数据库
/** * * @author lidelin 2017-03-03 * 连接数据库简单实例 * 准备工作:建项目工程,例如:test-jdbc;导入odbc6.jar */ public class ...
- ubuntu系统里vi编辑器时,按方向箭头输入是乱码的ABCD字母?(图文详解)
不多说,直接上干货! 问题详情 ubuntu系统里vi编辑器时,按方向箭头输入是乱码的ABCD字母? 解决办法 是由于预装的vim软件没更新,运行 sudo apt-get install vi ...
- 关于Bundle对象的思考
在开发过程中,我们经常使用bundle对象来携带二进制数据,通过INTENT传递出去,那么BUNDLE对象到底是什么?其结构如何? 简要来说,bundle对象类似于一个map,内部是通过<key ...
- chosen.jquery插件的使用
前几天在jQuery官网看到了插件里面有400多个插件,看了下效果都很好,以后项目里面难免会用到.于是下了个决定,有时间把官网的插件都研究下,并简单介绍他的用法,方便以后的使用. 下面将要提到的是jQ ...