神枪手JoneySun (Super hard version)
Description
神枪手JoneySun又双叒叕被邪恶derB_M困住了。不同的是这次他是被邪恶的B_M吃了下去,困在自己的身体里。
我们认为B_M的身体是一个n×m的矩形,矩形左下角的坐标为(0,0),左上角的坐标为(0,n),右下角坐标为(m,0),JoneySun被困在某个位置(但不在边缘上),幸运的是神枪手JoneySun被吞进来的时候还携带着他的枪,不幸的是他的枪只剩一发子弹了,由于是在B_M的身体中,所以子弹弹射到边界的时候会反弹,每次的反弹都会造成一定的伤害。只有造成了足够的伤害才能消灭邪恶的B_M,神枪手JoneySun才能逃出生天。
现在已知 n,m,JoneySun所在位置和子弹发射的向量速度,B_M能承受的最大伤害和每次碰撞所造成的伤害。问在 t 时刻JoneySun能否成功逃脱。
向量速度:如果起始位置在(x, y), 向量速度为(vx, vy), 那么经过 t 时间所处的位置在(x+t⋅vx,y+t⋅vy)
Input
第一行包括一个正整数 T (1≤T≤20),代表有多少组输入
每一组的第一行包括两个正整数 n (1≤n≤1e5) m (1≤m≤1e5)
每一组的第二行包括七个整数 x (1≤x<m), y (1≤y<n) , vx (−1e10 ≤ vx < 1e10), vy (−1e10 ≤ vy < 1e10), hp (0≤hp≤1e4), hu (0≤hu≤1e4), t (1≤t≤1e10), 代表JoneySun所在的位置, 子弹发射的向量速度, B_M所能承受的最大伤害, 每次碰撞所造成的伤害和时间t
Output
输出"Yes"代表可以逃脱
输出"No"代表不可以逃脱
Samples
input
1
10 10
1 1 1 2 1 1 1
output
No
Hint
题目保证在 t 之前不会反弹到任何一个顶点
题目保证 |t × vx| ≤ 1e18 , |t × vy| ≤ 1e18
为了简单起见,我们把子弹看作一个质点
Author
WEI, Wei
题解: 转化为马饮水问题,全部转化到一条直线,问题就转化成铺满n*m矩形的一个平面中这根线碰到几根边界,然后构造成一个三角形求解,如图,斜边碰到的数量就是两条直角边碰到的线的数量和。
#include<list>
#include<string.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
const int Base =131;
const ll INF = 1ll << 62;
//const double PI = acos(-1);
const double eps = 1e-7;
const int mod = 1e9+7;
#define speed {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); }
inline int gcd(int a, int b)
{
while (b ^= a ^= b ^= a %= b);
return a;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ll n,m;
scanf("%lld %lld",&n,&m);
ll x,y,vx,vy,hp,hu,t;
scanf("%lld %lld %lld %lld %lld %lld %lld",&x,&y,&vx,&vy,&hp,&hu,&t);
ll resx,resy,res=0,disx,disy;
resx=x+t*vx;
resy=y+t*vy;
disx=abs(resx-x);
disy=abs(resy-y);
if(resx>=m)
{
res++;
disx-=(m-x);
}
else if(resx<=0)
{
res++;
disx-=x;
}
res+=disx/m;
if(resy>=n)
{
res++;
disy-=(n-y);
}
else if(resy<=0)
{
res++;
disy-=y;
}
res+=disy/n;
//printf("%lld\n",res);
if(res*hu>hp)printf("Yes\n");
else printf("No\n");
}
system("pause");
return 0;
}