834 - Continued Fractions

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

Moderator: Board moderators

haaaz
New poster
Posts: 29
Joined: Sun Sep 08, 2002 8:02 am

834 - Continued Fractions

Post by haaaz » Sat Oct 05, 2002 5:23 pm

Can someone kindly provide me some test cases for p834-Continued Fractions ?

Thank you. :D

haaaz
New poster
Posts: 29
Joined: Sun Sep 08, 2002 8:02 am

Post by haaaz » Fri Oct 11, 2002 4:55 pm

I still got WA.
Anyone can provide me some tricky test inputs?

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin » Sun Oct 20, 2002 11:28 am

I don't know whether this problem has tricky inputs,but I can offer you some cases:
5 8
[0;1,1,1,2]
1684 6441
[0;3,1,4,1,2,2,3,12]
1 9
[0;9]
2 4
[0;2]
4898 215
[22;1,3,1,1,2,1,6]

good luck!!

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

834 - Continued Fractions

Post by boatfish » Sat Jul 12, 2003 3:43 pm

I have considered the cases for negative numbers, but still WA. why??

Code: Select all

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int a,b;
	float t;
	bool set;
	while(cin>>a>>b){
		set=false;
		t=a/float(b);
		if(t>=0){
			cout<<'['<<a/b<<';';
			a=a-a/b*b;
		}
		else{
			cout<<'['<<a/b-1<<';';
			a=fabs(b)-(fabs(a)-fabs(a/b*b));
			b=fabs(b);
		}
		while(a!=0){
			swap(a,b);
			cout<<a/b<<',';
			a=a-a/b*b;
			set=true;
		}
		if(set)
			cout<<"\b]\n";
		else
			cout<<"]\n";
	}
	return 0;
}

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Sun Jul 13, 2003 1:30 pm

consider the case,
4 2

your program gives
[2;]

The semi colon should not appear.

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

Post by boatfish » Sat Nov 01, 2003 9:00 am

Hi, I have handled that, but still WA. Why?
[cpp]#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
int a,b;
float t;
while(cin>>a>>b){
t=a/float(b);
if(t>=0){
cout<<'['<<a/b<<';';
a=a-a/b*b;
}
else{
cout<<'['<<a/b-1<<';';
a=fabs(b)-(fabs(a)-fabs(a/b*b));
b=fabs(b);
}
while(a!=0){
swap(a,b);
cout<<a/b<<',';
a=a-a/b*b;
}
cout<<"\b]\n";
}
return 0;
}[/cpp]

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer » Thu Jan 01, 2004 6:57 am

I've just solved this problem. I note that there are NO negative numbers in the input! So don't worry about that.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

Post by boatfish » Fri Jan 02, 2004 9:32 am

Observer wrote:I've just solved this problem. I note that there are NO negative numbers in the input! So don't worry about that.
Then why I keep on WA?

helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

NO negative numbers

Post by helmet » Wed Jun 16, 2004 1:31 pm

THERE ARE NO NEGATIVE NUMBERS!!!

I didnt even consider the case...though if num/den is a whole number remember not to output the ';'.
Just another brick in the wall...

Wei
New poster
Posts: 23
Joined: Sat Jul 24, 2004 5:37 pm
Contact:

834...with some questions

Post by Wei » Thu Oct 28, 2004 2:38 pm

Can anybody help me with these problems???
1.If the input is 2 1....What should I do for the output?? [2;]??? or what??
2.Is any negative number in the input????

Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA
Contact:

Post by Ryan Pai » Thu Oct 28, 2004 3:14 pm

1. My program crashed on this input
2. If the first number is negative my program crashes, if the denominator is negative it outputs the same numbers as if the denominator was positive, except they are all negative also.

From this I doubt that the judge's data includes true integers or negative numbers.
I'm always willing to help, if you do the same.

Wei
New poster
Posts: 23
Joined: Sat Jul 24, 2004 5:37 pm
Contact:

Post by Wei » Sun Oct 31, 2004 3:35 pm

Well~~I know the problem......
Thx for your answering!!!!

sohag144
New poster
Posts: 14
Joined: Mon Feb 27, 2006 4:12 pm
Location: Dhaka,Bangladesh
Contact:

834 nedd i/o

Post by sohag144 » Sun Apr 23, 2006 2:25 pm

can anyone give me huge input/output for this problem.

Timo
Learning poster
Posts: 70
Joined: Tue Oct 11, 2005 2:44 am
Location: Indonesia

Post by Timo » Mon Apr 24, 2006 7:26 am

Hi sohag144,
I have create random sample input and output from my AC program.
Hope it help you.

Input :

688 558
366 699
673 854
352 375
755 606
344 850
797 944
584 330
505 687
787 440
90 325
177 440
352 274
75 908
527 411
601 94
746 318
602 691
459 236
394 206
642 182
411 686
160 196
357 991
111 199
956 344
497 418
882 374
73 856
988 379
716 764
397 10
146 604
571 114
364 444
944 940
631 287
213 440
336 266
876 868
615 207
129 411
34 507
682 62
205 803
631 456
668 406
936 885
880 959
636 219
669 292
370 941
973 944
307 24
234 321
78 860
274 961
809 968
995 856
833 694
765 338
199 629
810 455
543 948
473 336
440 411
681 499
819 229
450 579
532 510
797 433
680 528
878 113
779 499
706 641
373 118
301 94
173 546
600 937
326 86
981 92
907 254
741 694
218 478
376 26
8 123
999 580
180 84
747 724
106 645
521 940
122 838
891 106
314 13
526 783
176 841
989 989
242 465
221 407
278 20


Output :

[1;4,3,2,2,1,2]
[0;1,1,10,11]
[0;1,3,1,2,1,1,4,1,1,2]
[0;1,15,3,3,2]
[1;4,14,1,9]
[0;2,2,8,10]
[0;1,5,2,2,1,2,3,2]
[1;1,3,2,1,12]
[0;1,2,1,3,2,3,1,1,2]
[1;1,3,1,2,1,2,1,1,3]
[0;3,1,1,1,1,3]
[0;2,2,17,5]
[1;3,1,1,19]
[0;12,9,2,1,2]
[1;3,1,1,5,3,3]
[6;2,1,1,5,1,2]
[2;2,1,8,6]
[0;1,6,1,3,4,5]
[1;1,17,6,2]
[1;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2,21,2,2,2]
[0;4,1,3,1,1,19]
[1]
[0;1,1,11,1,2,1,4]
[0;1,1,5,3,5,2]
[13;1,9]
"Life is more beautiful with algorithm"

sohag144
New poster
Posts: 14
Joined: Mon Feb 27, 2006 4:12 pm
Location: Dhaka,Bangladesh
Contact:

more input output

Post by sohag144 » Thu Apr 27, 2006 11:11 am

thank you. but can you give me some extra input output,like
-5 3
1 3
3 1
-25 6
0 2
2 0

more like this. in question says: To ensure uniqueness, make bn > 1.
can you explain with example?
:wink:

Post Reply

Return to “Volume 8 (800-899)”