147 - Dollars
Moderator: Board moderators
-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
147 - Dollars -- Wrong Answer
I cannot understand why this code is WA. Can anybody help me?
Here is my code
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
with best regards
------------------------
ishtiaq ahmed
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.
"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.
-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
147 - Dollars -- Wrong Answer
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
with best regards
------------------------
ishtiaq ahmed
Re: 147 - Dollars -- Wrong Answer
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.
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.
-
- Learning poster
- Posts: 53
- Joined: Sat Jul 29, 2006 7:33 am
- Location: (CSE,DU), Dhaka,Bangladesh
147 - Dollars -- Wrong Answer
Thanks a lot mf. I am nothing but a stupid one. Its a silly mistake.
Now its accepted.Again thank you.
Now its accepted.Again thank you.
No venture no gain
with best regards
------------------------
ishtiaq ahmed
with best regards
------------------------
ishtiaq ahmed
Re: 147. Strange.
phew..
guyz both of you saved me, i was getting mad from the WA error
but finally i made it with the ceil function and got accepted
it seems that float and double got some rounding errors, too bad..
but thanks anyway
guyz both of you saved me, i was getting mad from the WA error
but finally i made it with the ceil function and got accepted
Code: Select all
number=number*20;
number=ceil(number);
but thanks anyway
Why 147 WA?
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;
}
-
- New poster
- Posts: 28
- Joined: Mon Nov 15, 2004 5:00 pm
147 TLE despite working for all inputs instantaneously
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]);
}
}
}
Re: 147 TLE despite working for all inputs instantaneously
Search the board first. Use existing thread.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- 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
I cant figure out what is the problem of my code.
It simply gives me WA.
please help me.
advanced thnx
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;
}
http://www.newton.0fees.net is enough!
-
- New poster
- Posts: 20
- Joined: Thu Jan 17, 2008 10:47 pm
- Location: India
Re: why wa 147
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"
Re: why wa 147
Because you don't know how floating-point numbers work.