• Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分


    D. Vanya and Computer Game

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/492/problem/D

    Description

    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 Input

    4 3 2
    1
    2
    3
    4

    Sample Output

    Vanya
    Vova
    Vanya
    Both

    HINT

    题意

    Vanya每秒钟可以砍x刀,Vova每秒可以砍y刀

    有n次询问,给你一个怪兽的血量为ai,然后问你最后一刀是谁补的刀

    同时补刀,输出Both

    题解:

    二分是多少s砍死这只怪兽

    然后再check就好一下了~

    代码

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    
    int main()
    {
        int n;
        long long x,y;
        scanf("%d%lld%lld",&n,&x,&y);
        for(int i=0;i<n;i++)
        {
            long long a;scanf("%lld",&a);
            long long l = 0,r = 1LL<<60;
            while(l<=r)
            {
                long long mid = (l+r)/2LL;
                if(mid/x+mid/y>=a)r=mid-1;
                else l=mid+1;
            }
            if(l%x==0&&l%y==0)printf("Both
    ");
            else if(l%y==0)printf("Vanya
    ");
            else printf("Vova
    ");
        }
    }
  • 相关阅读:
    浅谈 C++ 多态性
    浅谈 C++ 继承
    C++ 深拷贝浅拷贝
    C++ 斐波那契数列
    C++ 指针函数和lambda
    设计模式之单例模式
    结构体中内存对齐和补齐
    AWS S3文件存储工具类
    Java Springboot学习(三) Thymeleaf 、mybatis-plus
    Java Springboot学习(三) 整合springmvc、jdbc、mybatis
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4970477.html
Copyright © 2020-2023  润新知