147 - Dollars

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

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

What if the input is 38.35?
Ami ekhono shopno dekhi...
HomePage
WingletE
New poster
Posts: 35
Joined: Sun Aug 13, 2006 1:34 pm
Location: Taipei, Taiwan
Contact:

Post by WingletE »

Thanks! I understand.
ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

147 - Dollars -- Wrong Answer

Post by ishtiaq ahmed »

I cannot understand why this code is WA. Can anybody help me?
Here is my code

Code: Select all

The code is removed after AC.
Last edited by ishtiaq ahmed on Fri Feb 22, 2008 1:51 pm, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

It has been already mentioned many times that you have to be very careful with rounding in this problem.

"n = (long long)(f / 0.05);" is a wrong way to round.
Decimals cannot generally be represented exactly in floating point, f/0.05 can be an epsilon smaller than the integer that you want, and thus get rounded to a smaller number. Learn ceil(), floor(), or round() functions, or add an epsilon to f/0.05 before rounding it the way you do.
ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

147 - Dollars -- Wrong Answer

Post by ishtiaq ahmed »

Thanks mf. I add epsilon but it still presentation error. Here is the code

Code: Select all

The code is removed after ac.
Last edited by ishtiaq ahmed on Fri Feb 22, 2008 1:52 pm, edited 1 time in total.
No venture no gain

with best regards
------------------------
ishtiaq ahmed
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 147 - Dollars -- Wrong Answer

Post by mf »

Presentation Error at this judge means that you have too many whitespaces somewhere in your output.

Change your printf format so that it would exactly match sample output. There should be two right-justified fields of sizes 6 and 17, in columns 1..6 and 7..23. No other whitespaces anywhere.
ishtiaq ahmed
Learning poster
Posts: 53
Joined: Sat Jul 29, 2006 7:33 am
Location: (CSE,DU), Dhaka,Bangladesh

147 - Dollars -- Wrong Answer

Post by ishtiaq ahmed »

Thanks a lot mf. I am nothing but a stupid one. Its a silly mistake.
Now its accepted.Again thank you.
No venture no gain

with best regards
------------------------
ishtiaq ahmed
wmqwj
New poster
Posts: 4
Joined: Thu Aug 14, 2008 3:32 am
Contact:

Re: 147. Strange.

Post by wmqwj »

phew.. :o
guyz both of you saved me, i was getting mad from the WA error :evil:
but finally i made it with the ceil function and got accepted

Code: Select all

      number=number*20;
      number=ceil(number);
it seems that float and double got some rounding errors, too bad..
but thanks anyway :D
chiu1234
New poster
Posts: 2
Joined: Sat Aug 02, 2008 7:06 am

Why 147 WA?

Post by chiu1234 »

Code: Select all

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

int main(){
  long long result[6001];
  float input  = 0.0f;
  int ans;
  int notes[] = {1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000};
  result[0] = 1;
  for (int i = 1; i <= 6000; i++){
    result[i] = 0; 
  }   
  for (int j = 0; j < 11; j++){    
    for (int i = notes[j]; i <= 6000; i++){
      result[i] += result[i - notes[j]];
    }

  }

  while(scanf("%f", &input)){
    if (input == 0) break;
    ans = (int)ceil((input * 20));
    
    printf("%6.2f%17I64d\n", input, result[ans]);
  }
  
  return 0;
}
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: Why 147 WA?

Post by Jan »

Search the board first. Use an existing thread.
Ami ekhono shopno dekhi...
HomePage
SePulTribe
New poster
Posts: 28
Joined: Mon Nov 15, 2004 5:00 pm

147 TLE despite working for all inputs instantaneously

Post by SePulTribe »

My code below works perfectly fine with a file with inputs from 5c to $300 instantaneously but the online judge keeps complaining of TLE. Does anybody know why?

Code: Select all

import java.util.Arrays;
import java.util.Scanner;

class Main
{
	private static long values[] = new long[6001];
	private final static int[] currency = { 1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000  };

	public static void main(String args[])
	{
		int ii, c, jj;
		final Scanner stdin = new Scanner(System.in);

		Arrays.fill(values, 0);
		values[0] = 1;
		for (ii = 0; ii < 11; ii++)
		{
			c = currency[ii];
			for (jj = c; jj <= 6000; jj++)
				values[jj] += values[jj - c];
		}

		while (stdin.hasNextLine())
		{
			String temp = stdin.nextLine();
			double in = new Scanner(temp).nextDouble();
			if (temp.trim().compareTo("0.00") == 0)
				break;
			System.out.printf("%6s%17d\n", temp, values[((int) Math.round(in * 100)) / 5]);
		}
	}
}
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 147 TLE despite working for all inputs instantaneously

Post by Jan »

Search the board first. Use existing thread.
Ami ekhono shopno dekhi...
HomePage
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 147 __int64 can't hold big results.Please help

Post by newton »

I cant figure out what is the problem of my code.
It simply gives me WA.
please help me.

Code: Select all

#include <cstdio>
#include <cmath>
#include <algorithm>
#define MAX 6001
#define eps 1e-7
using namespace std;


int coins[] = {1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000};
unsigned long long ways[MAX];

void setWays(){
	int i,j;
	ways[0] = 1;
	for (j = 0; j < 11; j++){   
		for (i = coins[j]; i <= MAX; i++){
			ways[i] = ways[i] + ways[i - coins[j]];
		}
	}
}

int main(){	
	double input;
	int ans;	
	setWays();
	while(scanf("%lf", &input) && input > eps){		
		ans = (int)ceil((input * 20));		
		printf("%6.2f%17llu\n", input, ways[ans]);
	}	
	return 0;
}
advanced thnx
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

Re: why wa 147

Post by theharshest »

Why WA :(

Code: Select all

#include<iostream>
using namespace std;

int coins[]={5,10,20,50,100,200,500,1000,2000,5000,10000};
long long nw[30001];

int main()
{

	nw[0]=1;

	for(int i=0;i<11;i++)
	{
		int c=coins[i];
		for(int j=c;j<=30000;j++)
			nw[j]=nw[j]+nw[j-c];
	}

	float n;

	while(1)
	{
		cin>>n;

		if(n==0.00)
			break;	

		int m=n*100;

		printf("%6.2f%17lld\n",n,nw[m]);
	}	
}
"if u r goin thru hell, keep goin"
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: why wa 147

Post by mf »

Because you don't know how floating-point numbers work.
Post Reply

Return to “Volume 1 (100-199)”