HTML & JS
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define key pair<int, int>
#define ff first
#define ss second
const  int mod = 1e9 + 7;
const int inf = 1e18;
using namespace std;

double equal(double x, double y)   // for checking equality. 
{
    if(abs(x - y) <= 1e-8)
        return true;
    return false;    
}

main()
{
    fastread;
    int n; cin>>n;
    double x, y; cin>>x>>y;
    x = 1/x; y = 1/y;
//    cout<<setprecision(20)<<x<<" "<<y<<"\n";
    while(n--)
    {
        double h; cin>>h;
        double st = 0, end = 1e9, idx;
        f(i, 1, 200)
        {
            double m = (st + end)/2;
            int t = (int)(m/x) + (int)(m/y);
        //    cout<<t<<" "<<m<<"\n";
            if(t >= h)
            {
                idx = m; end = m;
            }
            else
                st = m;
        }
        double xht = idx/x, yht = idx/y;   // counting the number of hits. 
        int xh = xht, yh = yht;

        if(equal(xht, ceil(xht)))   // if it is very much close to making another hit, then vanya hits another time.    
            xh = ceil(xht);
        if(equal(yht, ceil(yht)))   
            yh = ceil(yht);

        if(equal(xh*x, idx) && equal(yh*y, idx))    //both hits at the same time
            cout<<"Both\n";
        else if(equal(xh*x, idx))
            cout<<"Vanya\n";
        else if(equal(yh*y, idx))
            cout<<"Vova\n";
        else                // just to find if its working. 
            cout<<"aaa";
    }
}

Generated URL:

Output:

Vanya
Vova
Vanya
Both
Report Bug