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;
    }
  • 相关阅读:
    一步一步制作jquery插件Tabs(ajax只请求一次效果,78行完成)
    javascript没那么简单
    jQuery插件制作备忘
    封装jQuery表格插件jqGrid,控件化jqGrid(二):显示
    shell脚本day01bash的基本特性
    pythonday01_语言元素
    pythonday01_环境搭建
    shell脚本作业
    [转]ADS简要教程
    极限挑战—C#+ODP 100万条数据导入Oracle数据库仅用不到1秒
  • 原文地址:https://www.cnblogs.com/jhz033/p/5917613.html
Copyright © 2011-2022 走看看