697 - Jack and Jill

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

Moderator: Board moderators

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

697 - Jack and Jill

Post by angga888 »

I have passed all sample inputs correctly, but still WA :(

Please someone give me the total time required for these inputs :
1 1 1 1 1 1 1
1 1 1 1 1 1 2
2 2 2 5 2 2 2
2 2 2 2 2 2 5

And if you don't mind, please give me another tricky inputs.

Thx for helping me.

Regards,
angga888
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Here is output for your input from my accepted program:

Code: Select all

Scenario 1:
     up hill               1.00 sec
     well diameter         1.00 in
     water level           1.00 in
     bucket volume         1.00 cu ft
     bucket ascent rate    1.00 in/sec
     down hill             1.00 sec
     required volume       1.00 cu ft
     TIME REQUIRED         3.07 sec

Scenario 2:
     up hill               1.00 sec
     well diameter         1.00 in
     water level           1.00 in
     bucket volume         1.00 cu ft
     bucket ascent rate    1.00 in/sec
     down hill             1.00 sec
     required volume       2.00 cu ft
     TIME REQUIRED      2209.61 sec

Scenario 3:
     up hill               2.00 sec
     well diameter         2.00 in
     water level           2.00 in
     bucket volume         5.00 cu ft
     bucket ascent rate    2.00 in/sec
     down hill             2.00 sec
     required volume       2.00 cu ft
     TIME REQUIRED         5.10 sec

Scenario 4:
     up hill               2.00 sec
     well diameter         2.00 in
     water level           2.00 in
     bucket volume         2.00 cu ft
     bucket ascent rate    2.00 in/sec
     down hill             2.00 sec
     required volume       5.00 cu ft
     TIME REQUIRED      1670.98 sec
Only one hint -- don't compare volume with zero, i.e. use something do { ... } while (volumeleft > 1e-7); (I've got WA earlier because of this reason).
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

My output is all correct according to yours.
I also have changed my program with do {...} while (volumeleft>1e-7)
But still WA. Why ?
Maybe I am wrong in formatting output.
I use this as my output.

printf("Scenario@%d:\n",o);o++;
printf("@@@@@up@hill@@@@@@@@@@@@%7.2lf@sec\n",up);
printf("@@@@@well@diameter@@@@@@%7.2lf@in\n",d);
printf("@@@@@water@level@@@@@@@@%7.2lf@in\n",l);
printf("@@@@@bucket@volume@@@@@@%7.2lf@cu@ft\n",b);
printf("@@@@@bucket@ascent@rate@%7.2lf@in/sec\n",p);
printf("@@@@@down@hill@@@@@@@@@@%7.2lf@sec\n",down);
printf("@@@@@required@volume@@@@%7.2lf@cu@ft\n",v);
printf("@@@@@TIME@REQUIRED@@@@@@%7.2lf@sec\n\n",time);

/* @ shows space */

Please tell me if my output is wrong.
Thanx.

Regards,
angga888
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Your output looks OK, so I don't know why you haven't got AC...

What's you're using for PI value? In my solution I've used pi = acos(-1).
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho »

Ivan Golubev,

If you don't mind, can you tell me how you figure out you need
do { ... } while (volumeleft > 1e-7);

Thanks!
Abednego
A great helper
Posts: 281
Joined: Tue Sep 10, 2002 5:14 am
Location: Mountain View, CA, USA
Contact:

Post by Abednego »

Ivan is saying that you need to be careful when dealing with floating point numbers that are close to zero. Instead of a do{...} while( V > 1e-7), you can also compute the number of trips required like this:

Code: Select all

int trips = ( int )ceil( V / B - 0.000000000001 );
Then simulate while( trips-- ){...}. Also, to have some protection against enormous inputs, this is what I do for the output.

Code: Select all

        printf( "Scenario %d:\n", ++prob );
        printf( "     up hill         %10.2f sec\n", UP );
        printf( "     well diameter   %10.2f in\n", D );
        printf( "     water level     %10.2f in\n", L );
        printf( "     bucket volume   %10.2f cu ft\n", B );
        printf( "     bucket ascent rate%8.2f in/sec\n", P );
        printf( "     down hill       %10.2f sec\n", DOWN );
        printf( "     required volume %10.2f cu ft\n", V );
        printf( "     TIME REQUIRED   %10.2f sec\n", t );
I hope this helps.
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho »

Thank You For Your explaination!
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

697: Jack & Jill

Post by sumankar »

Code: Select all

[c]#include<stdio.h>
#include<math.h>

#define PI (acos(-1))
#define G  (32.2)
#define _FT (1.0/12.0)

double process(double up, double d, double l, double b, double p, double down, double v)
{
	double dl, t, downT, upT;
	int i, n;

	n = v/b;
	if( v > n*b )
		n++;
	t = n*(up + down);
	downT = upT = 0.0;
	dl = (4*b)/(PI*d*d);
	for( i = 0; i < n; i++ ) {
		downT += sqrt(l);
		upT += l/p;
		l += dl;
	}
	downT *= sqrt(2/G);
	t += (upT + downT);
	return t;
}

int main()
{
	int i, times, scene;
	double UP, DOWN, P, B, D, L, V, T;
	
	scene = 0;
	while( scanf("%lf",&UP) == 1 ) {
		if( UP < 1.0 )
			exit(0);
		scanf("%lf %lf %lf %lf %lf %lf", &D, &L, &B, &P, &DOWN, &V);
		scene++;
		printf("Scenario %d:\n", scene);
		printf("     up hill	        %6.2lf sec\n", UP);
		printf("     well diameter	%6.2lf in\n", D);
		printf("     water level	%6.2lf in\n", L);
		printf("     bucket volume 	%6.2lf cu ft\n", B);
		printf("     bucket ascent rate	%6.2lf in/sec\n", P);
		printf("     down hill		%6.2lf sec\n", DOWN);
		printf("     required volume	%6.2lf cu ft\n", V);
		D *= _FT;
		L *= _FT;
		P *= _FT;
		T = process(UP, D, L, B, P, DOWN, V);
		printf("     TIME REQUIRED	%6.2lf sec\n\n", T);
	}	
		
	return 0;
}
[/c]
my code passes Golubev's i/o
What else can be wrong?
Plz HELP
thnx,
suman.
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho »

I am not sure if that's it, but you can try put in tolerance, where
while(v>n*b) -> while(v>n*b-1e-7)
sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

697

Post by sumankar »

i submitted some other tolerance -added src
which was acc.
But that one gives the same answers as the one iI've pasted over here.
Starnge!!
suman.
beeplove
New poster
Posts: 17
Joined: Tue Sep 30, 2003 9:28 pm
Location: Boston, MA, USA
Contact:

Post by beeplove »

Can anybody please post more sample input and output.

In output, is there any "\n" after last scenario?
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho »

should be a \n
but it only gives you PE if you miss spacing, you still solves the problem
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

697: What is wrong

Post by aakash_mandhar »

Can anyone tell me what is wrong.. Need help badly. It gives a wa but i have tested with the inputs given in this page...

Thx in advance..
[cpp]

# include<iostream.h>
# include<math.h>
# include<stdio.h>

double PI=acos(-1);

double UP,D,L,B,P,DOWN,V,R;
double TIME;
double ROUNDS,i;
double DINC;
int nt=0;





void print() {
printf( "Scenario %d:\n", ++nt );
printf( " up hill %10.2f sec\n", UP );
printf( " well diameter %10.2f in\n", D );
printf( " water level %10.2f in\n", L );
printf( " bucket volume %10.2f cu ft\n", B );
printf( " bucket ascent rate%8.2f in/sec\n", P );
printf( " down hill %10.2f sec\n", DOWN );
printf( " required volume %10.2f cu ft\n", V );




}


int main()
{

while(cin>>UP)
{
TIME=0;
if(UP==0.0) break;
cin>>D>>L>>B>>P>>DOWN>>V;
ROUNDS=ceil(V/B-1e-7);
R=D/2.0;
TIME=ROUNDS*(UP+DOWN);
DINC=(B*1728.0)/(PI*R*R);
print();
for(i=0;i<ROUNDS;i++)
{
TIME+=(sqrt((2.0*L)/(32.2*12.0)) + L/P);
L+=DINC;
}
printf( " TIME REQUIRED %10.2f sec\n", TIME );
printf("\n");
}
return 1;
}

[/cpp]
...I was born to code...
yiuyuho
A great helper
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States
Contact:

Post by yiuyuho »

read carefully:
A line containing a single value less than one appears following the data for the last scenario.
aakash_mandhar
New poster
Posts: 38
Joined: Thu Dec 11, 2003 3:40 pm
Location: Bangalore

697 WA Oops just cant get it

Post by aakash_mandhar »

I did the changes as u said but still got WA. Can you post the part of the code which handles the terminating condition <1.0 coz it says a sngle line having number less than 1. I am unable to handle the case.. Plz help

Do i get te same outputs as your AC solution..

Thx..

[cpp]

# include<iostream.h>
# include<math.h>
# include<stdio.h>

double PI=acos(-1);

double UP,D,L,B,P,DOWN,V,R;
double TIME;
double ROUNDS,i;
double DINC;
int nt=0;



void print() {
printf( "Scenario %d:\n", ++nt );
printf( " up hill %10.2f sec\n", UP );
printf( " well diameter %10.2f in\n", D );
printf( " water level %10.2f in\n", L );
printf( " bucket volume %10.2f cu ft\n", B );
printf( " bucket ascent rate%8.2f in/sec\n", P );
printf( " down hill %10.2f sec\n", DOWN );
printf( " required volume %10.2f cu ft\n", V );




}


int main()
{

while(cin>>UP)
{
TIME=0;

cin>>D>>L>>B>>P>>DOWN>>V;

if(UP<1.0 && cin.eof()) break; /* i use eof to check if stream has ended . I guess the problem lies here .*/
ROUNDS=ceil(V/B-1e-7);
R=D/2.0;
TIME=ROUNDS*(UP+DOWN);
DINC=(B*1728.0)/(PI*R*R);
print();
for(i=0;i<ROUNDS;i++)
{
TIME+=(sqrt((2.0*L)/(32.2*12.0)) + L/P);
L+=DINC;
}
printf( " TIME REQUIRED %10.2f sec\n", TIME );
printf("\n");
}
return 1;
}


[/cpp]
...I was born to code...
Post Reply

Return to “Volume 6 (600-699)”