10450 - World Cup Noise

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

Moderator: Board moderators

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion »

Thanks, Turuthok.
Got AC now. :lol: :lol:
Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

10450 why WA?

Post by Zhao Le »

i have tried my ways but still got WA.
i know someone use long long but i still got WA
i here use double and precision set to zero.
but still failed, who can help me?
Here is my code.
----------------------------------
#include <iostream.h>
#define Max 51

double S[Max]={2,3};

void Cal()
{
int i;
for(i=2;i<Max;i++)
S=S[i-1]+S[i-2];
}

void main()
{
Cal();
int n;
cin>>n;
while(n--)
{
int i;
cin>>i;
cout<<"Scenario #"<<i<<":"<<endl;
cout.setf(ios::fixed);
cout.precision(0);
cout<<S[i-1]<<endl<<endl;
}
}
Monzer Hossain
New poster
Posts: 1
Joined: Tue Aug 20, 2002 5:57 pm
Location: Bangladesh

Post by Monzer Hossain »

cout<<"Scenario #"<<i<<":"<<endl;

In this line i is wrong.
Here should be a counter for number of current input
which starts from 1 instead of i which is input. :wink:

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

Post by Observer »

It's nice to see that so many various problems can be solved by Fibonacci Numbers!!

If there are more such prob. in ACM, tell me!!!

Btw, when n = 50, the answer should contain 11 digits.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Thanatos
New poster
Posts: 5
Joined: Tue Mar 09, 2004 11:14 am

10450 WA - why?

Post by Thanatos »

Hey guys, I did the World Cup problem and did figure out why the answer was a Fibonacci number. So i coded this...

[cpp]
#include <iostream>
#include <math.h>

using namespace std;

long long fibo(int x)
{
return (long long)((pow((1+sqrt(5.))/2,x)-pow((1-sqrt(5.))/2,x))/sqrt(5.));
}

int main()
{
int x,i=1;
while (cin >> x)
cout << "Scenario #" << i++ << endl << fibo(x+2) << endl << endl;
return 0;
}[/cpp]

But i get WA?! Yes there is a formula for fibonacci's number and it does work...anyone help please?[/cpp]
alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

Post by alu_mathics »

I think what you generate ,its an approximate value of fibo n.
You can use the general recursive formula.
that is
fibo[n]=fibo[n-1]+fibo[n-2];
Hope this will help you
cuii e
worldguy
New poster
Posts: 4
Joined: Sat May 07, 2005 2:31 pm
Location: China

Post by worldguy »

I tried to solve this problem using the long long type but failed. Well, when I shifted long long type to double type, I got it accepted. I'm wondering, why long long type gives out the incorrect answers?
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel »

Hello friends....
I want to solve this problem....it was only the trick of fibonacci num...
I save them in an array. and compare each of the input of above....and all same....
But my program get WA why....?
I cant understand I use double too...
Here is my code.....Please Checked the code....

Code: Select all

#include<stdio.h>
double array[60];
void fibonacci(long a)
{
	 long i;
	 array[0]=0;
	 array[1]=1;
	 for(i=2;i<=a;i++)
	 {
			array[i]=array[i-1]+array[i-2];
	 }
}
int main()
{
	int input,n,i;
	//freopen("d:\\10450.txt","r",stdin);
	fibonacci(55);
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
			scanf("%d",&input);
			if(input==0)
				printf("0\n");
			else
				printf("%0.lf\n",array[input+2]);
	}
	return 0;
}
I hate Wrong Answer!
vinit_iiita
New poster
Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm
Contact:

Post by vinit_iiita »

I am getting damn stupid WA ??..

Code: Select all

#include <iostream> 
#include <cmath> 
using namespace std; 
int main() 
{ 
int x,i=1;
int n;
cin>>n; 
while (i<=n){
cin >> x; 
long long int a,b,c;
a=1;b=1;
for (int j=3;j<=x+2;j++)
{
    int t;
    t=a;
    a=a+b;
    b=t;
}
cout << "Scenario #" << i++ <<":"<< endl << a << endl << endl; 
}
return 0; 
}
plz help me out...
win
kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:

Post by kolpobilashi »

you need to change following things:

Code: Select all

for (int j=3;j<=x+2;j++) 
{ 
    int t; 
    t=a; 
    a=a+b; 
    b=t; 
} 
in the above part declare j and t as long long.
moreover, for

Code: Select all

x=0
a=0
but yours one gives 1.

hope you'll get AC :)
Sanjana
vinit_iiita
New poster
Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm
Contact:

Post by vinit_iiita »

thanx i got ac :D
win
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10450 - World Cup Noise

Post by Obaida »

Code: Select all

Accepted
Last edited by Obaida on Sat Nov 01, 2008 6:56 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10450 - World Cup Noise

Post by Jan »

Just think that how many times the recursive calls being used? Say, for n = 6 you have to calculate for both 5 and 4, again for 5 you have to calculate both 4 and 3. 4 is calculated twice. So, if you think a while you will find that the number of calls are increasing exponentially.
Ami ekhono shopno dekhi...
HomePage
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 10450 - World Cup Noise

Post by Obaida »

Thanks jan bi.
i got acc. :wink:
try_try_try_try_&&&_try@try.com
This may be the address of success.
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 10450 - World Cup Noise

Post by newton »

Its a simple Java code
but ONLINEJUDGE says me RE!!
why can u find plz.

Code: Select all

import java.util.*;
import java.io.*;
import java.math.BigInteger;

class WorldCup{		
	WorldCup(){};	
	public static void main(String args[]){
		int i,n,num;
		BigInteger B[] = new BigInteger[55];
		Scanner sc = new Scanner(System.in);
				
		B[0] = new BigInteger("1");
		B[1] = new BigInteger("2");
		for(i = 2; i< 55; i++){
			B[i] = B[i-1].add(B[i-2]);			
		}
		n = sc.nextInt();
		for(i = 1; i <= n; i++){
			num = sc.nextInt();
			System.out.println("Scenario #"+i+":\n"+B[num]);
			System.out.println("");		
		}
	}
}
Post Reply

Return to “Volume 104 (10400-10499)”