CodeForces 492D Vanya and Computer Game [二分]

题意:有N只怪物,每只的血量为Ai,现在有两个人攻击力都为1,Vanya攻速为1秒X下,Vova攻速为每秒Y下,问每只怪物最后是被谁杀死的,如果一起打出最后一下,输出Both。

范围:N<=10的5次,X,Y<=10的6次,Ai<=10的9次

解法:二分很容易想到,只要二分是什么时刻打死怪物就好了,只是数据非常恶心,十分难AC,尝试了各种姿势才A..


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n;
double x,y;
double eps=1e-6;
void getans(double val){
    double l=0.0,r=val/max(x,y)+eps;
    rep(i,1,100){
        double m=(l+r)/2.0;
        if(floor(m*x)+floor(m*y)>=val)r=m;
        else l=m;
    }
    double xx=floor(l*x+eps);
    double yy=floor(l*y+eps);
    if(xx*y==yy*x)printf("Both\n");
    if(xx*y>yy*x)printf("Vanya\n");
    if(xx*y<yy*x)printf("Vova\n");
}
int main(){
    scanff(n);
    scanff(x);
    scanff(y);
    rep(i,1,n){
        double temp;
        scanff(temp);
        getans(temp);
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值