Final Round (Open Div. 2)A,B,C
阿新 • • 發佈:2018-12-20
感覺這場的題面都好長,看的腦殼子疼(英語不好,啊我掛了
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