10357 - Playball !!!

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

10357 - Playball !!!

Post by lowai »

can anyone give some data?
[pascal]
var
nplayer, nball, code : integer;
player : array[1..20, 1..3]of longint;
i : integer;
a, b, c, d, e, f, g : double;
x, y : double;
r, t : double;
s : string;

function ceiling(x : double) : double;
begin
if abs(int(x) - x) < 1e-7 then
ceiling := x
else
ceiling := int(x) + 1;
end;

function caught : boolean;
var i : integer; dis : double;
begin
for i := 1 to nball do
begin
dis := sqr(x - player[i, 1]) + sqr(y - player[i, 2]);
if dis <= sqr(t) * sqr(player[i, 3]) then
begin caught := true; exit; end;
end;
caught := false;
end;

begin
readln(s); delete(s, 1, 8);
val(s, nplayer, code);
for i := 1 to nplayer do
readln(player[i, 1], player[i, 2], player[i, 3]);

readln(s); delete(s, 1, 6);
val(s, nball, code);
for i := 1 to nball do
begin
readln(a, b, c, d, e, f, g);
r := b * b - 4 * a * c;
t := (-b - sqrt(r)) / (2 * a);
t := ceiling(t);
x := d * t + e;
y := f * t + g;
if (x < 0) or (y < 0)then
writeln('Ball ', i, ' was foul at (', x :0 :0, ',', y:0:0, ')')
else
if caught then
writeln('Ball ', i, ' was caught at (', x :0 :0, ',', y:0:0, ')')
else
writeln('Ball ', i, ' was safe at (', x :0 :0, ',', y:0:0, ')')
end;

end.
[/pascal]
daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Try converting dis to an integer.
Rafa3p
New poster
Posts: 5
Joined: Sun Dec 25, 2011 1:32 am

10357 - Playball !!!

Post by Rafa3p »

HI, i'm finding the position where the ball hit the ground, but i'm having
problem to determine if the ball was "safe" or "caught".
I run my vector of players looking if someone can take the ball before it hit the ground

T1 <= T2 T1->Player running T2->Time to ball hit the ground, that i used to found x,y
S/V <= T2 s->distance between player and ball(z=0)
S<=T2*V v->player velocity
S² <= T2²*V²
then,
(player.x - x)² + (player.y - y) ² <= player.v² * t²

Code: Select all

#include <stdio.h>
typedef struct
{
    int x,y,v;
}PLAYER;
int main(void)
{
    int a,b,c,d,e,f,g; /*ball status*/
    int i,j,n,balls,t;

    PLAYER team[20];
    scanf("PLAYERS=%d",&n);
    for(i=0;i<n;i++)
        scanf("%d %d %d",&team[i].x,&team[i].y,&team[i].v);

    scanf(" BALLS= %d ",&balls);
    for(j=1;i<=balls;j++)
    {
        scanf("%d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g);
        for(t=1;a*t*t+b*t+c>0;t++){} /*finding the time when (ball height) z<=0*/
        a = d*t+ e; /*x position when the ball hit the ground*/
        b = f*t+ g; /*y position when the ball hit the ground*/
        if((a<0) || (b<0))
        {
            printf("Ball %d was foul at (%d,%d)\n",i,a,b);
            continue; /*Invalid position*/
        }
        for(i=0;i<n;i++)
        {
            c = team[i].x-a; /*distance² = c²+d²*/
            d = team[i].y-b;
            if( c*c + d*d <= t*t+team[i].v*team[i].v)      /*if d<vt, then d²<v²t²*/
                break;
        }
        if(i==n) printf("Ball %d was safe at (%d,%d)\n",j,a,b);
        else printf("Ball %d was caught at (%d,%d)\n",j,a,b);
    }
    return 0;
}
Rafa3p
New poster
Posts: 5
Joined: Sun Dec 25, 2011 1:32 am

Re: 10357 - Playball !!!

Post by Rafa3p »

I found three stupid mistakes and got AC
1) for(j=1;i<=balls;j++) -> for(j=1;j<=balls;j++)
2) if( c*c + d*d <= t*t+team.v*team.v) -> if( c*c + d*d <= t*t*team.v*team.v)
3)printf("Ball %d was foul at (%d,%d)\n",i,a,b) -> printf("Ball %d was foul at (%d,%d)\n",j,a,b)


Delete the post?
Hikari9
New poster
Posts: 20
Joined: Tue Jan 22, 2013 4:39 pm

Re: 10357 - Playball !!!

Post by Hikari9 »

This is a pretty stupid problem. At first, I was struggling to find out "which" time t to pick when the two t's I get from quadratic function (z=at^2+bt+c) are nonnegative.

Look at Ball 5 and 8 as an example...

Ball 5:
t = 0 or 1
( uses t=0 ????? )
Ball 8:
t = 0 or 1.25
( uses t=1.25 ????? )

Just saying. What I did was make up some excuse function for that specific input to work WITHOUT using the quadratic function... then got AC
Looped through all integers until z>0. Hope this will help those who got WA :D
Post Reply

Return to “Volume 103 (10300-10399)”