Codeforces Round #280 (Div. 2)

D.Vanya and Computer Game

Difficulty\mathtt{Difficulty}=1800\mathtt{1800}
这道题目不难想到用二分答案解决,
我们考虑二分 boss\texttt{boss} 死亡的时间,
不难得到式子 Hit=T/X+T/Y
而显然这个东西是具有单调性的,
所以我们的算法没有假。
而知道时间以后,
我们只要判一下是否整除,
就可以判断是谁进行了最后致命一击。
于是代码就不难写出了。

#include<bits/stdc++.h>
#define BetterIO ios::sync_with_stdio(false)
using namespace std;
#define int long long
int X,Y;
signed main(void)
{
	BetterIO;
	register int Case;cin>>Case>>X>>Y;while(Case--)
	{
		register int A;cin>>A;
		register int Left(0),Right(LONG_LONG_MAX),Ret;
		while(Left<Right)
		{
			register int Mid((Left+Right)>>1);
			if(Mid/X+Mid/Y>=A)Right=Ret=Mid;
			else Left=Mid+1;
		}
		if(!(Ret%X)&&!(Ret%Y)){cout<<"Both"<<endl;continue;}
		if(!(Ret%X)){cout<<"Vova"<<endl;continue;}
		if(!(Ret%Y)){cout<<"Vanya"<<endl;continue;}
	}
	return 0;
}