zoukankan      html  css  js  c++  java
  • CodeForces 492D 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.

    Sample test(s)
    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.

    思路: 首先找出循环节,循环节的次数就是 x/=gcd(x,y), y/=gcd(x,y) , 然后对于 a, a要跟x+y取余,如果a==0 或者 a==x+y-1就代表同时杀死。否则就模拟一遍,第几步攻击的是谁。

    注意,要用longlong

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    //const int INF = 1e9;
    const double eps = 1e-6;
    const int N = 3*1000000;
    ll cas = 1;
    
    char s[][10]={"Vanya","Vova","Both"};
    int who[N];
    ll n,x,y;
    
    ll gcd(ll a,ll b)
    {
        return b?gcd(b,a%b):a;
    }
    
    void run()
    {
        ll g = gcd(x,y);
        x /= g;
        y /= g;
        ll xy = x+y;
        swap(x,y);
        ll xx = x, yy = y;
        for(ll i = 1; i<=xy ; i++)
        {
            if(xx < yy)
            {
                who[i] = 0;
                xx += x;
            }
            else
            {
                who[i] = 1;
                yy += y;
            }
        }
        ll a;
        for(ll i = 1; i <= n; i ++ )
        {
            scanf("%I64d",&a);
            a %= xy;
            if(a==0 || a==xy-1)
                puts(s[2]);
            else
                puts(s[who[a]]);
        }
    }
    
    int main()
    {
        #ifdef LOCAL
        freopen("case.txt","r",stdin);
        #endif
        while(scanf("%I64d%I64d%I64d",&n,&x,&y)!=EOF)
            run();
        return 0;
    }
  • 相关阅读:
    net下 Mysql Linq的使用, 更新数据,增加数据,删除数据
    mysql net连接读取结果为乱码 Incorrect string value
    ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
    CBQW ---分组表单展示
    infopath 之绑定列表 数据源
    Office365 InfoPath 表单的设计和应用(原创)
    [转]如何管理一个远程团队
    [转]以《AI War》为例阐述AI元素概念与代码
    [转]分享AI寻径设计的射线追踪法
    [转]如何反推一个游戏
  • 原文地址:https://www.cnblogs.com/someblue/p/4136435.html
Copyright © 2011-2022 走看看