zoukankan      html  css  js  c++  java
  • Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 数学

    D. Vanya and Computer Game
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1 / x seconds for the first character and 1 / y seconds for the second one). The i-th monster dies after he receives ai hits.

    Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.

    Input

    The first line contains three integers n,x,y (1 ≤ n ≤ 105, 1 ≤ x, y ≤ 106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.

    Next n lines contain integers ai (1 ≤ ai ≤ 109) — the number of hits needed do destroy the i-th monster.

    Output

    Print n lines. In the i-th line print word "Vanya", if the last hit on the i-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.

    Examples
    input
    4 3 2
    1
    2
    3
    4
    output
    Vanya
    Vova
    Vanya
    Both
    input
    2 1 1
    1
    2
    output
    Both
    Both
    Note

    In the first sample Vanya makes the first hit at time 1 / 3, Vova makes the second hit at time 1 / 2, Vanya makes the third hit at time 2 / 3, and both boys make the fourth and fifth hit simultaneously at the time 1.

    In the second sample Vanya and Vova make the first and second hit simultaneously at time 1.

     题意:va每秒可以打x次,vo每秒可以打y次,求第a[i]次是谁打的;

    思路:循环节为x/gcd(x,y)+y/gcd(y,z);

       离线处理,最多2e6次左右,余数暴力;

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=2e5+10,M=4e6+10,inf=1e9+10,mod=1e9+7;
    int ans[N];
    struct is
    {
        int a;
        int pos;
        bool operator <(const is &b)const
        {
            return a<b.a;
        }
    }a[N];
    int gcd(int x,int y)
    {
        return y==0?x:gcd(y,x%y);
    }
    int main()
    {
        int n,x,y;
        scanf("%d%d%d",&n,&x,&y);
        int len=x/gcd(x,y)+y/gcd(x,y);
        for(int i=1;i<=n;i++)
        scanf("%d",&a[i].a),a[i].a%=len,a[i].pos=i;
        sort(a+1,a+n+1);
        int va=0;
        int vo=0;
        double xx=1.0/x;
        double yy=1.0/y;
        for(int i=1;i<=n;i++)
        {
            while(va+vo<a[i].a)
            {
                if(va*xx+xx<vo*yy+yy)
                va++;
                else
                vo++;
            }
            ans[a[i].pos]=(va*xx-vo*yy>eps?1:-1);
            if(a[i].a==len-1||a[i].a==0)ans[a[i].pos]=0;
        }
        for(int i=1;i<=n;i++)
        if(ans[i]==1)
            printf("Vanya
    ");
        else if(ans[i]==0)
            printf("Both
    ");
        else
            printf("Vova
    ");
        return 0;
    }
  • 相关阅读:
    Selenium IDE安装及环境搭建教程
    菜鸟学自动化测试(一)----selenium IDE
    seleniumIDE回放找不到页面元素
    selenium报错汇总
    利用saltstack初始化OpenStack服务器环境
    工作机会
    使用state模块部署lamp架构
    tar命令
    svn备份
    MAC电脑密码破解
  • 原文地址:https://www.cnblogs.com/jhz033/p/5917613.html
Copyright © 2011-2022 走看看