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

    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 time2 / 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.


    这题思路不难,我的思路是先找出最后一秒t,然后m减去(t-1)*(x+y),然后二分最后一秒。但是这题非常卡精度,非常坑啊。


    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<string>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    #define inf 0x7fffffff
    #define eps 1e-9
    #define eps1 1e-6
    
    double x,y,m;
    int cal1(double shijian)
    {
        int i,j,num1,num2;
        int l=0;
        int r=x,mid;
        while(l<=r){
            mid=(l+r)/2;
            if(1.0*mid*(1.0/(x*1.0) )>shijian )r=mid-1;
            else l=mid+1;
        }
        return r;
    }
    
    
    int cal2(double shijian)
    {
        int i,j,num1,num2;
        int l=0;
        int r=y,mid;
        while(l<=r){
            mid=(l+r)/2;
            if(1.0*mid*(1.0/ (1.0*y) )>shijian )r=mid-1;
            else l=mid+1;
        }
        return r;
    
    }
    
    int main()
    {
        int n,i,j,t1,num11,num22,h;
        double l,r,mid;
        int num1,num2;
        while(scanf("%d%lf%lf",&n,&x,&y)!=EOF)
        {
            for(h=1;h<=n;h++){
                scanf("%lf",&m);
                t1=m/(x+y);
                m-=(x+y)*t1;
                l=0;r=1;
                for(i=1;i<=200;i++){
                    mid=(l+r)/2.0;
                    num1=cal1(mid);
                    num2=cal2(mid);
                    if(num1+num2>=m)r=mid;
                    //if(floor(mid*x)+floor(mid*y)>=m)r=mid;
                    else l=mid;
                }
                double num3=floor(mid*x+eps);
                double num4=floor(mid*y+eps);  //这里不加eps会错的= =
                if(num3*y==num4*x)printf("Both
    ");
                else if(num3*y>num4*x)printf("Vanya
    ");
                else if(num3*y<num4*x)printf("Vova
    ");
            }
        }
        return 0;
    }


  • 相关阅读:
    IC79620: USER'S ROUTINE MAY BE TERMINATED ABNORMALLY IF SOME SYSTEMROUTINES WERE RUN IN DB2FMP BEFORE
    SQL1042C running a fenced routine (stored procedure/UDF)
    新创建的数据库,执行db2look时,遇到package db2lkfun.bnd bind failed
    【转载】JSP生成静态Html页面
    【新闻发布系统】项目文档
    【新闻发布系统】登录和注销的实现
    【tomcat】关于tomcat的使用:将tomcat加入系统服务列表
    【JavaWeb】JSP九大内置对象
    【学习笔记】JDBC数据库连接技术(Java Database Connectivity)
    【学习笔记】2017年7月18日MySQL测试:模拟QQ数据库
  • 原文地址:https://www.cnblogs.com/herumw/p/9464618.html
Copyright © 2011-2022 走看看