Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2)A,B,C

感觉这场的题面都好长,看的脑壳子疼(英语不好,啊我挂了

http://codeforces.com/contest/1075

A. The King's Race

考虑对角线为分界


#include <iostream>
using namespace std;
int main() {
	long long n,x,y;
	cin>>n>>x>>y;
	if((x+y)<=n+1)cout<<"White";
	else cout<<"Black";
	return 0;
}

B. Taxi drivers and Lyft

每个0都会选择离他近的1,预处理一下每个0的前后最近的1的位置,然后跑一边就能算出每个0应该会归属哪个1了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll n,m;
ll res[maxn];
struct T{
	ll pre;
	ll last;
}tt[maxn];
ll x[maxn];
ll type[maxn];
int main(){
	scanf("%lld%lld",&n,&m);
	for(int i=0;i<n+m;++i){
		scanf("%lld",x+i);
	}
	for(int i=0;i<n+m;++i){
		scanf("%lld",type+i);
	}
	ll pp=-1e9;
	for(int i=0;i<n+m;++i){//更新前驱 
		if(type[i]==0){
			tt[i].pre=pp;
		}
		else{
			pp=i;
		} 
	}
	ll la=1e9+5;
	for(int i=n+m-1;i>=0;--i){//更新后继 
		if(type[i]==0){
			tt[i].last=la;
		}
		else{
			la=i;
		} 
	}
	
	for(int i=0;i<m+n;++i){
		if(type[i]==0){
			if(tt[i].last==1e9+5){
				res[tt[i].pre]++;
			}
			else if(tt[i].pre==(-1e9)){
				res[tt[i].last]++;
			}
			else{
				ll xx=x[i]-x[tt[i].pre];
				ll yy=x[tt[i].last]-x[i];
				if(xx<=yy){
					res[tt[i].pre]++;
				}
				else{
					res[tt[i].last]++;
				}
			}
		}
	}
	for(int i=0;i<n+m;++i){
		if(type[i]==1){
			cout<<res[i]<<' ';
		}
	}
	return 0;
}




C. The Tower is Going Home

    单独写了一下https://blog.youkuaiyun.com/TDD_Master/article/details/83960783

 

后面的题交的人好少,立个flag,来补

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值