zoukankan      html  css  js  c++  java
  • cf492D 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枪,第二个人每秒开y枪,下面给出n个询问,问boss血量ai的时候谁打出最后一下

    首先x、y约分。因为题目只要求最后的结果,那么假设x=g*x0,y=g*y0,g>1

    那么问题可以转换为“第一个人每1/g秒开x0枪,第二个人每1/g秒开y0枪”

    实际上是一样的

    那么直接打表暴力搞出1~x0+y0的胜负情况,然后O(1)输出

    因为数组开小而RE3次……蛋疼

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<deque>
    #include<set>
    #include<map>
    #include<ctime>
    #define LL long long
    #define inf 0x7ffffff
    #define pa pair<int,int>
    #define pi 3.1415926535897932384626433832795028841971
    using namespace std;
    inline LL read()
    {
        LL x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,nx=1,ny=1;
    int mod,x,y;
    int ans[3000010];
    inline int gcd(int a,int b)
    {return b==0?a:gcd(b,a%b);}
    int main()
    {
    	n=read();x=read();y=read();
    	int g=gcd(x,y);
    	x/=g;y/=g;
    	mod=x+y;
    	for (int i=1;i<=mod;i++)
    	{
    		LL aa=(LL)nx*y,bb=(LL)ny*x;
    		if (aa<bb && nx<=x)ans[i]=1,nx++;
    		else if (aa>bb && ny<=y)ans[i]=-1,ny++;
    		else
    		{
    			i++;
    			nx++;
    			ny++;
    		}
    	}
    	ans[0]=ans[mod];
    	for (int i=1;i<=n;i++)
    	{
    		int query=read();
    		query%=mod;
    		if (ans[query]==1)printf("Vanya
    ");
    		else if (ans[query]==-1)printf("Vova
    ");
    		else printf("Both
    ");
    	}
    	return 0;
    }
    
    ——by zhber,转载请注明来源
  • 相关阅读:
    IDEA常用快捷键(常用)
    mysql命令
    mysql localhost能连上ip连不上
    Spring Boot2部署jar包
    host localhost is not allowed ... 1130错误
    纯真ip数据库
    微软Windows XP 正版验证通知去除的工具以及手工清除办法
    周一好困哦!!!
    SQL 连接字符串的说明(转)
    IP地址和数字之间转化的算法
  • 原文地址:https://www.cnblogs.com/zhber/p/4136462.html
Copyright © 2011-2022 走看看