It very easy problem... but why WA?
One has to calucate Cathalan numbers <21 and just print it number.
What is wrong with my algo?
Can somebody publish a few inputs?
10223 - How many nodes ?
Moderator: Board moderators
-
- Experienced poster
- Posts: 146
- Joined: Sat Apr 26, 2003 2:51 am
-
- Experienced poster
- Posts: 146
- Joined: Sat Apr 26, 2003 2:51 am
Thanks!
Thanks!
I have already got AC.
I have already got AC.
10223 -- what is the difference
sorry to send the codes but i have failed to find out the difference between these two codes.
this one got AC
#include <stdio.h>
void main()
{
register int i, j;
unsigned long n, arr[32];
for(i = arr[0] = 1; i < 20; i++){
for(j = arr = 0; j < i; j++)
arr += arr[j] * arr;
}
while(scanf("%lu",&n) == 1){
for(i = 1; i < 20; i++){
if(arr == n)
break;
}
printf("%d\n", i);
}
}
this one got WA
#include<stdio.h>
int main()
{
unsigned long A,array[20];
int i;
//array[0] = 1;
array[1] = 1;
array[2] = 2;
array[3] = 5;
array[4] = 14;
array[5] = 42;
array[6] = 132;
array[7] = 429;
array[8] = 1430;
array[9] = 4862;
array[10] = 16796;
array[11] = 58786;
array[12] = 208012;
array[13] = 742900;
array[14] = 267440;
array[15] = 9694845;
array[16] = 35357670;
array[17] = 129644790;
array[18] = 477638700;
array[19] = 1767263190;
//array[20] = 6564120420;
while( scanf("%lu",&A) != EOF )
{
for( i=1 ; i<20 ; i++ )
if( array == A )
{
printf("%d\n",i);
break;
}
}
return 0;
}
sorry again and of course thanks
this one got AC
#include <stdio.h>
void main()
{
register int i, j;
unsigned long n, arr[32];
for(i = arr[0] = 1; i < 20; i++){
for(j = arr = 0; j < i; j++)
arr += arr[j] * arr;
}
while(scanf("%lu",&n) == 1){
for(i = 1; i < 20; i++){
if(arr == n)
break;
}
printf("%d\n", i);
}
}
this one got WA
#include<stdio.h>
int main()
{
unsigned long A,array[20];
int i;
//array[0] = 1;
array[1] = 1;
array[2] = 2;
array[3] = 5;
array[4] = 14;
array[5] = 42;
array[6] = 132;
array[7] = 429;
array[8] = 1430;
array[9] = 4862;
array[10] = 16796;
array[11] = 58786;
array[12] = 208012;
array[13] = 742900;
array[14] = 267440;
array[15] = 9694845;
array[16] = 35357670;
array[17] = 129644790;
array[18] = 477638700;
array[19] = 1767263190;
//array[20] = 6564120420;
while( scanf("%lu",&A) != EOF )
{
for( i=1 ; i<20 ; i++ )
if( array == A )
{
printf("%d\n",i);
break;
}
}
return 0;
}
sorry again and of course thanks
Try hard . May be you will get the right answer.
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10223 - How Many Nodes?
A thing I've notices that,for my code given below, when I give input 1767263190,it should print 19..but it prints nothing... I think that's why I am getting WA... Would anybody tell me please,why it happens for input 1767263190 ???
Code: Select all
Accepted... :)
Last edited by Mukit Chowdhury on Wed Nov 07, 2012 8:37 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10223 - How Many Nodes?
Don't compare doubles using ==. Instead use something like:
#include <math.h>
if(fabs(c-n)<0.5)
http://acm.uva.es/p/float-in-competition.pdf
#include <math.h>
if(fabs(c-n)<0.5)
http://acm.uva.es/p/float-in-competition.pdf
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 99
- Joined: Fri Aug 17, 2012 9:23 pm
- Location: Dhaka
- Contact:
Re: 10223 - How Many Nodes?
Thanks brianfy713... Got the point... 
