# HDU-5572-An Easy Physics Problem

ACM模版

## 代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double EPS = 1e-8;

int cmp(double x)
{
if (fabs(x) < EPS)
{
return 0;
}
else
{
return x > 0 ? 1 : -1;
}
}

typedef struct node
{
double x, y;

{
scanf("%lf%lf", &x, &y);
}
} point, speed;

point PA, PB;
speed SA;

struct circle
{
point o;
int r;

{
scanf("%lf%lf%d", &o.x, &o.y, &r);
}
} C;

node operator + (node a, node b)
{
return {a.x + b.x, a.y + b.y};
}

node operator - (node a, node b)
{
return {a.x - b.x, a.y - b.y};
}

node operator * (double p, node a)
{
return {a.x * p, a.y * p};
}

double dot(node a, node b)
{
return a.x * b.x + a.y * b.y;
}

double dis(node a)
{
return sqrt(dot(a, a));
}

double cross(node a, node b)
{
return a.x * b.y - b.x * a.y;
}

node GetLine(node P, node A, node B)
{
node V = B - A;
node ans = A + (dot(V, P - A) / dot(V, V)) * V;
return ans;
}

double d;

void GetAnglePoint(point PA, speed SA, circle C)
{
node A = PA, B = PA + SA;
if (dis(C.o - B) > dis(C.o - A))
{
A = PA + SA;
B = PA;
}

if (cmp(d - C.r) < 0)
{
double l = sqrt((double)C.r * C.r - d * d);
AngleA = head + l / dis(B - A) * (B - A);
AngleB = head - l / dis(B - A) * (B - A);
}
}

int main()
{
int T;
scanf("%d", &T);

for (int ce = 1; ce <= T; ce++)
{
printf("Case #%d: ", ce);

GetAnglePoint(PA, SA, C);
if (cmp(d - C.r) >= 0)
{
if (cmp(cross(PB - PA, SA)) == 0 && cmp(dot(PB - PA, SA)) > 0)
{
puts("Yes");
}
else
{
puts("No");
}
continue;
}

node N;
if (cmp(dis(AngleA - PA) - dis(AngleB - PA)) < 0)
{
N = AngleA;
}
else
{
N = AngleB;
}

int flag = 0;
if (cmp(cross(PA - PB, N - PB)) == 0 && cmp(dot(PA - PB, N - PB)) <= 0)
{
flag = 1;
}

node tmp = GetLine(PA, C.o, N);
point PA2 = PA + 2 * (tmp - PA);
speed SA2 = N - PA2;
if (cmp(cross(PB - N, SA2)) == 0 && cmp(dot(PB - N, SA2)) <= 0)
{
flag = 1;
}

if (flag)
{
puts("Yes");
}
else
{
puts("No");
}
}

return 0;
}

101 篇文章37 人订阅

0 条评论

## 相关文章

2452

2437

1593

### 数据挖掘知识脉络与资源整理(九)–柱形图

? 柱形图 简介 英文：histogram或者column diagram 排列在工作表的列或行中的数据可以绘制到柱形图中。在柱形图中，通常沿水平轴组织类别，...

31210

5138

903

1394

4038

1223

1642