Codeforces 492D Vanya and Computer Game【模拟+循环节+思维】好题~

75 篇文章 0 订阅

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 ≤ 1051 ≤ 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.


题目大意:

现在一共有N个敌人,每个敌人都可以承受Ai次攻击,对应有两个变量X,Y,表示第一个人一秒内可以攻击敌人X次,那么对应攻击一次的时间花费为1/X。

同理,第二个人一秒内可以攻击敌人Y次,那么对应攻击一次的时间花费为1/Y。

问每个敌人都会先被哪个人打死。

如果是一起打死的,那么对应输出Both、否则输出对应的人名。


思路:


1、首先确定,我们如果预处理1e9内所有操作,显然会超时。那么考虑如何优化这个模拟过程。


2、考虑这样一个问题,两个人轮流输出的过程中,一定会有同时打死敌人的情况发生。

我们可以考虑的稍微极限一些,对应第一个人一秒攻击X次,第二个人一秒攻击Y次,那么对应第一秒的时候.两个人肯定会同时攻击敌人一次。

观察到X,Y><=1e6,那么很显然,我们如果单单预处理1s以内的攻击情况然后对应将输入进来的ai进行判断取摸是可行的。


3、那么我们考虑最终思路:

①预处理第一次共同攻击敌人之前的情况。对应记录下最终时刻time、

②那么对应输入进来的ai,首先对time取摸,然后输出预处理完的解。

③注意一个点,如果两个人同时打敌人一次,那么对应相当于在这个时刻,输出为2,、

那么对应样例输入:

1 3 2

5

输出也是Both.


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
ll n,x,y;
int ans[10000060];
ll fenzia,fenmua,fenzib,fenmub,time;
void init()
{
    fenzia=1;
    fenmua=x;
    fenzib=1;
    fenmub=y;
    time=1;
    while(1)
    {
        if(fenzia*fenmub>fenzib*fenmua)
        {
            ans[time]=2;
            fenzib++;
        }
        else if(fenzia*fenmub<fenzib*fenmua)
        {
            ans[time]=1;
            fenzia++;
        }
        else
        {
            ans[time]=0;
            time++;
            return ;
        }
        time++;
    }
}
int main()
{
    while(~scanf("%I64d%I64d%I64d",&n,&x,&y))
    {
        init();
        for(int i=0;i<n;i++)
        {
            int tmp;
            scanf("%d",&tmp);
            tmp%=time;
            if(tmp==0||ans[tmp]==0)printf("Both\n");
            else if(ans[tmp]==1)printf("Vanya\n");
            else if(ans[tmp]==2)printf("Vova\n");
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值