[UVA] 10357 - Playball !!!
Problem E
Playball !!!
Input: standard input
Output: standard output
Time Limit: 1 second
Memory Limit: 32 MB
While on a trip to the US, you decide to stop by Atlanta and get to the baseball stadium where the Braves are playing a decisive baseball game against the NY Mets.
According to the players' position on the field, they may catch the balls that are hit by the batters, if they can get there on time before the ball touches the ground. The ball's position follows the following simple mathematical equations:
For the ball: z = at2+bt + c - a,b,..,g are
constants given for each ball hit. |
Each player has an individual starting position (xo, yo) he always returns to before a new ball is hit. The players, each starting to run as soon as the ball is hit towards the correct position where the ball will eventually touch the ground, all theoretically have a chance to catch the ball. So you must verify all of them since the distance they can run is dependant on their individual speed. Well, after all, we assume that these players always run as fast as possible given the good paychecks they are given, so the variation of their position is always the same throughout the match, e.g. they run at the same speed.
Important notes:
- A ball that ends up touching the ground n the negative side of the ground axis (x or y) is said to be "foul" and can not be caught. These cases are trivial but must be taken care of.
- The time the ball takes to travel (t) is the smallest integer that satisfies the equation of the height of the ball, i.e. t is the first positive integer for which z becomes zero or negative. This integer is the time when the ball is considered to hit the ground.
- A ball "not caught" before it touches the ground is said to be "safe".
- The maximum number of players is less than 20 players, but could be any number below that limit.
Input
The format of the input is the following (where all parameters are integer values):
PLAYERS=#
// number of players/lines to read
x y
v
// x,y - startup position of the player; v - the speed of the player
...
// for each player
BALLS=#
// Number of balls that are hit
a b c d e f
g
// Parameters according to the ball equations
...
// for each ball
Output
The output should consist of one line per ball following the format:
"Ball i was ??? at (xkor,ykor)", where i is the ball number, ??? is one of caught, safe, or foul, and (xkor,ykor) is the coordinates where the ball hit the ground. Look at the example below!
Sample Input
PLAYERS=9
0 0 3
16 16 2
30 0 4
36 24 4
0 30 3
24 36 5
24 75 7
75 24 6
60 60 7
BALLS=12
-1 3 1 21 3 14 5
-1 1 1 11 3 2 5
-3 4 0 8 5 11 2
-1 2 1 -4 1 6 7
-1 1 0 9 3 14 5
-2 4 1 32 3 12 5
-1 1 1 11 1 19 5
-4 5 0 18 5 20 5
-1 2 1 24 5 6 7
-1 1 0 9 3 4 1
-2 2 1 2 5 22 5
-1 6 1 10 5 13 5
Sample Output
Ball 1 was caught at (87,61)
Ball 2 was safe at (25,9)
Ball 3 was safe at (21,24)
Ball 4 was foul at (-11,25)
Ball 5 was safe at (12,19)
Ball 6 was safe at (99,41)
Ball 7 was caught at (23,43)
Ball 8 was safe at (41,45)
Ball 9 was caught at (77,25)
Ball 10 was safe at (12,5)
Ball 11 was safe at (9,49)
Ball 12 was caught at (75,96)
Ghyslain Pelletier
題目描述:
一個三維空間,發生在第一象限,如果球飛出這個象限,則輸出 foul
而落地時間要當計算為第一個整數使得球地於地面,接著此時的 x, y 才是落地的地方。
查看所有球員是否能在時限內抵達 x, y。
#include <stdio.h>
#include <math.h>
int main() {
int n, m;
int i, j, k;
int x[1005], y[1005], v[1005];
int cases = 0;
scanf("PLAYERS=%d", &n); {
for(i = 0; i < n; i++)
scanf("%d %d %d", &x[i], &y[i], &v[i]);
while(getchar() != '\n');
scanf("BALLS=%d", &m);
int a, b, c, d, e, f, g;
while(m--) {
scanf("%d %d %d %d", &a, &b, &c, &d);
scanf("%d %d %d", &e, &f, &g);
if(a < 0) a = -a, b = -b, c = -c;
int t = (int)ceil(((-b)+sqrt(b*b-4*a*c))/(2.0*a));
int xx = d*t+e;
int yy = f*t+g;
if(t < 0) t = 0;
printf("Ball %d was ", ++cases);
if(xx < 0 || yy < 0)
printf("foul");
else {
int caught = 0;
for(i = 0; i < n; i++) {
if((int)hypot(xx-x[i], yy-y[i])/v[i] < t)
caught = 1, i = n;
}
if(caught)
printf("caught");
else
printf("safe");
}
printf(" at (%d,%d)\n", xx, yy);
}
}
return 0;
}
/*
PLAYERS=9
0 0 3
16 16 2
30 0 4
36 24 4
0 30 3
24 36 5
24 75 7
75 24 6
60 60 7
BALLS=12
-1 3 1 21 3 14 5
-1 1 1 11 3 2 5
-3 4 0 8 5 11 2
-1 2 1 -4 1 6 7
-1 1 0 9 3 14 5
-2 4 1 32 3 12 5
-1 1 1 11 1 19 5
-4 5 0 18 5 20 5
-1 2 1 24 5 6 7
-1 1 0 9 3 4 1
-2 2 1 2 5 22 5
-1 6 1 10 5 13 5
*/