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 »

That's why its better to print doubles like

Code: Select all

printf("%0.lf",x+eps); 
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
sunny_boy_in
New poster
Posts: 1
Joined: Fri Aug 17, 2007 12:22 am
Location: India
Contact:

TLE...Plz Help.

Post by sunny_boy_in »

My code gives TLE. Please help

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

int main()
{
while(1) {
int dec=0,frac=0;
scanf("%d.%d",&dec,&frac);
long value=(dec*100+frac);
if(value==0) break;
double val;
unsigned long long ways[7001][11];
memset(ways,0,sizeof(ways));

if(value%5!=0) {
ways[value][10]=0;
val=value/100.00;
}
else {
value/=5;
int coins[11]={1,2,4,10,20,40,100,200,400,1000,2000};
for(int i=0;i<11;i++) ways[0]=1;
for(int i=1;i<=value;i++) {
for(int j=0;j<11;j++) {

unsigned long long type1=(j==0?0:ways[j-1]);
unsigned long long type2=(i>=coins[j]?ways[i-coins[j]][j]:0);
ways[j]=type1+type2;

}

}

val=value/20.0;
}
printf("%6.2lf%17llu\n",val,ways[value][10]);
}
return 0;
}
rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Post by rhsumon »

Why Compile error???
I can't imagin about this.......

Code: Select all

Removed after AC
plz notify someone about this.......
Last edited by rhsumon on Tue Sep 25, 2007 4:56 pm, edited 2 times in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

I think 'void main' is the problem. You must use

Code: Select all

int main()
{
    // bla bla bla
    return 0;
}
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Post by rhsumon »

I've forgot about this but now also it gives me PE

What can i do plz .............
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Edit : The correct format is given below.
Last edited by Jan on Tue Sep 25, 2007 11:02 am, edited 1 time in total.
Ami ekhono shopno dekhi...
HomePage
rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Post by rhsumon »

But that line first i submitted
It was a presentation Error......
After that i gave this one........
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

I haven't understood you fully. Why did you use %10lld?
Ami ekhono shopno dekhi...
HomePage
rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Post by rhsumon »

I mean first field width is 6 so to set last field width to 17 it's need to add more 10 width so that i printed that.......

At first i printed 6 and 17 but that was also PE

So what can i do?

Give me some trics.......
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Try this one (Sorry, I was wrong :-? )

Code: Select all

printf("%6.2lf%17lld\n",n+1e-7,nway[amnt]);
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
rhsumon
New poster
Posts: 48
Joined: Wed Aug 23, 2006 12:29 pm
Location: Dhaka

Post by rhsumon »

I cannot understand why this was a PE ......... It should have WA .......
Am i wrong?? Plz give some info about it.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Your previous code was correct except the formatting. The 1e-7 was given for safety, nothing else. Check carefully, you used %17lld but there was a space behind it. :) So, it was PE.
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 »

Code: Select all

(int)(n * 100.0 + 1e-6)
Would it be the reason of wrong answer?
Or there might be other errors in my code?

Please give me some more tricky test cases.
Thanks!
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

I can't think of any tricky case. You can post your code.
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 »

Here's my code.
I use the same method as problem 357.
I really don't know where could be wrong...

Code: Select all

Code deleted!!!
Thanks for checking it for me!
Last edited by WingletE on Sun Nov 18, 2007 8:25 am, edited 1 time in total.
Post Reply

Return to “Volume 1 (100-199)”