ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1258. Pool

I kill you, Test 12!!!!!!
Posted by DAVE 16 Oct 2007 15:33
#include <stdio.h>
#include <math.h>
#include <string.h>

int X1,Y1,X2,Y2,W,D,X,Y;
double P;

int l,r,f,b,first_l,first_f,last_l,last_f,N;
char c[10010];

int main()
{
int i;
scanf("%d %d %d %d %d %d",&W,&D,&X1,&Y1,&X2,&Y2);
scanf("%s",c);
N=strlen(c);
for (i=0; i<N; ++i)
{
if (c[i]=='L') { first_l=1;    break; }
if (c[i]=='R') { first_l=0;    break; }
}
for (i=0; i<N; ++i)
{
if (c[i]=='L') last_l=1;
if (c[i]=='R') last_l=0;
}
for (i=0; i<N; ++i)
{
if (c[i]=='F') { first_f=1;    break; }
if (c[i]=='B') { first_f=0;    break; }
}
for (i=0; i<N; ++i)
{
if (c[i]=='F') last_f=1;
if (c[i]=='B') last_f=0;
}
for (i=0; i<N; ++i)
{
if ((c[i]=='L') || (c[i]=='R')) l++;
if ((c[i]=='F') || (c[i]=='B')) f++;
}
if (l>0)
{
X=(l-1)*W;
if (first_l==1) X+=X1; else X+=W-X1;
if (last_l==1) X+=X2; else X+=W-X2;
}
else X=X1-X2;
if (f>0)
{
Y=(f-1)*D;
if (first_f==1) Y+=Y1; else Y+=D-Y1;
if (last_f==1) Y+=Y2; else Y+=D-Y2;
}
else Y=Y1-Y2;
P=sqrt((double)X*X+Y*Y);
printf("%.4lf",P);
return 0;
}
Re: I kill you, Test 12!!!!!!
Posted by Howl of Despair 16 Jan 2008 19:59
I think problem is this:
P=sqrt((double)X*X+Y*Y);
In 12th test 'int' will oveflow during multiplication.
Just think of __int64.