http://118.190.162.167/p1012.html
题目描述
两个英雄互相攻击,两个英雄血量为a、b,攻击力为x、y,伤害减免为p、q,攻速分别为v、 w。谁会赢?
血量:就是总生命值,当这个值变为零时死亡。
攻击力:在对方伤害减免为零时,每次攻击使得对方减少的生命值。
伤害减免:可以减小或免除对方的攻击效果,对方攻击使得我方减少的实际生命值=max(0,对方攻击力-我方伤害减免)。A对B的实际伤害为max(0,x-q)。
攻速表示:每两次之间的间隔,攻击本身瞬间完成。
当两个人同时攻击对方并导致死亡时,认为同时死亡,在第0时刻就可以发动第一次攻击。
更多细节参考输入输出样例。
数据范围
小数据:
整数a, b: 1<=a, b<=10000
整数x, y: 1<=x, y<=10000
整数p, q: 0<=p<=y, 0<=q<=x
两位小数 v, w: 0.01<=v=w<=10.00
大数据:
整数a, b: 1<=a, b<=1000000000
整数x, y: 1<=x, y<=10000
整数p, q: 0<=p<=10000, 0<=q<=10000
两位小数 v, w: 0.01<=v, w<=10.00
输入描述
第一行一个整数t(t<=100),代表有t组。
之后t行,每行有8个数a, b, x, y, p, q, v, w。
输出描述
每组数据,若A赢输出“A”,若B赢输出“B”,如果两个人同时死或者都不死输出“Draw”。
思路如下:计算两位英雄砍死对方需要的攻击次数,再乘以对应的攻速计算出相应的时间,通过时间判断输赢。需要注意的是,n次攻击对应的时间为(n-1)*攻速。同时,若两位英雄最后一次攻击对应的时间为同一时刻,则需判断是否会同时死亡:
AC代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
int num;
float a1,a2; //for big data check
int x1,x2,p1,p2;
int after_a1,after_a2;
float v1,v2;
float t1,t2; //kill other time
float t11,t22;//last attack
freopen("input.txt","r",stdin);
cin>>num;
while(num--)
{
cin>>a1>>a2>>x1>>x2>>p1>>p2>>v1>>v2;
if(((x1-p2)<=0)||(x2-p1)<=0)
{
if(((x1-p2)<=0)&&(x2-p1)<=0)cout<<"Draw"<<endl;
else if((x1-p2)<=0)cout<<"B"<<endl;
else cout<<"A"<<endl;
}
else
{
t1=(ceil(a2/(x1-p2))-1)*v1;
t2=(ceil(a1/(x2-p1))-1)*v2;
after_a2=a2-(ceil(a2/(x1-p2))-1)*(x1-p2);
after_a1=a1-(ceil(a1/(x2-p1))-1)*(x2-p1);
if(t1<t2)
{
cout<<"A"<<endl;
}
if(t2<t1)
{
if((t1-v1)==(t2-v2))
{
if(after_a2<=(x1-p2))cout<<"Draw"<<endl;
else cout<<"B"<<endl;
}
else cout<<"B"<<endl;
}
if(t2==t1)
{
if((after_a2<=(x1-p2))&&(after_a1<=(x2-p1)))
cout<<"Draw"<<endl;
}
}
}
return 0;
}