forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10357.cpp
72 lines (69 loc) · 1.15 KB
/
10357.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
struct Player
{
int x, y, v;
} p[20];
int no, balls;
int main()
{
char str[80];
int i, j;
gets(str);
for (i = 0; !isdigit(str[i]); i++)
;
no = atoi(str + i);
for (i = 0; i < no; i++)
{
gets(str);
sscanf(str, "%d %d %d", &p[i].x, &p[i].y, &p[i].v);
}
gets(str);
for (i = 0; !isdigit(str[i]); i++)
;
balls = atoi(str + i);
for (i = 0; i < balls; i++)
{
int a, b, c, d, e, f, g;
int x, y, tt;
double t;
gets(str);
sscanf(str, "%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g);
double D = sqrt(b * b - 4 * a * c);
t = (-b - D) / 2 / (double)a;
if (t < 0)
{
t = (-b + D) / 2 / (double)a;
}
tt = (int)t;
if (a * tt * tt + b * tt + c > 0)
{
tt++;
}
printf("Ball %d was ", i + 1);
x = d * tt + e;
y = f * tt + g;
if (x < 0 || y < 0)
{
printf("foul at (%d,%d)\n", x, y);
continue;
}
for (j = 0; j < no; j++)
{
int dx = x - p[j].x, dy = y - p[j].y;
if (dx * dx + dy * dy <= p[j].v * p[j].v * t * t)
{
break;
}
}
if (j == no)
{
printf("safe at (%d,%d)\n", x, y);
}
else
{
printf("caught at (%d,%d)\n", x, y);
}
}
return 0;
}