11038 - How Many O's?

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

Moderator: Board moderators

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

11038 - How Many O's?

Post by Darko »

I didn't manage to solve it yesterday, but now I have no idea what is wrong. I get the sample right, can someone check this I/O:

Code: Select all

1001010101 1010101010
3020203 302010203
-1 -1

Code: Select all

20991740
151899207
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

My program outputs:

Code: Select all

23709830
231396207
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Thanks a bunch! Instead of 10^i in one place, I had just 10, but it was OK for the sample input.
midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra »

hi, I have difficulty with this problem
I think it in this way:
from 0..9 I have one 0
from 0..99 I have ten 0's
so I think it in this way:
cant representes amount of 0's from 0..(10^i - 1)
so I have
cant[1]=1
cant[2]=10
for(i=3;i<11;i++)
cant=9*(cant[i-1]+pow(10,i-2)) + cant[i-1];

I though this:
suppouse this two numbers of n-digits: 100..00 and 999..99
from 100..00 to 999..99 (both of n-digits)
the amount of 0's is 9*(100..00 to 199..99)
and the amount of 0's from 100..00 to 199..99 is equal to cant[n-1] + pow(10,n-2)
this is because, from 100..00 to 199..99 we can forgive the first digit and count the amount of 0's of the rest (n-1)digits and then I sum pow(10,n-2) because I am counting the case where 10x..xx I mean, first digit 1, second digit 0 and the rest of digits can be anything because this case is not in the amount of cant[n-1] because in amount of 0's of cant[n-1] I don't count numbers that start with 0
the problem is that when I calculate this with brute force, I get another results, and I am not sure if this is the correct idea to solve this problem...maybe there are more elegant and efficient solutions...
I really appreciate any help!!
thanks for reading!
bye!

PD: I hope you understand my ugly explanation
plz let me know if you don't understand some part of my explanation
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

midra wrote: for(i=3;i<11;i++)
cant=9*(cant[i-1]+pow(10,i-2)) + cant[i-1];

I don't think the highlighted part is correct. For instance, if i=4 the number of uncounted leading zeros in numbers 7000, 7001, ... 7009, 7010, ... 7047, ... 7099, 7100, ... 7999 is 110 and not pow(10,i-2)=100.
midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra »

thanks...I think I understand my error
I really apreciate your help!
SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

Post by SRX »

hi , I have solved this prob , and I use cin as input way

Why if I use
"scanf ( "%lld %lld" , &n , &m ) and scanf ( "%I64d , %I64d" , &n , &m )"
, I get tle

Can someone answer me ?
thanks :D
studying @ ntu csie
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

SRX wrote:hi , I have solved this prob , and I use cin as input way

Why if I use
"scanf ( "%lld %lld" , &n , &m ) and scanf ( "%I64d , %I64d" , &n , &m )"
, I get tle
I have used the scanf to read the input, too, but without any problem with the time limit. Just make sure not to write the colon in "%I64d , %I64d"!
SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

Post by SRX »

Martin Macko wrote:
SRX wrote:hi , I have solved this prob , and I use cin as input way

Why if I use
"scanf ( "%lld %lld" , &n , &m ) and scanf ( "%I64d , %I64d" , &n , &m )"
, I get tle
I have used the scanf to read the input, too, but without any problem with the time limit. Just make sure not to write the colon in "%I64d , %I64d"!

Code: Select all

#include <iostream>
#include <cstdio>
#include <algorithm>
using std :: cout ; 
long long n , m ; 
int main () { 
 while ( scanf ( "%I64d %I64d" , &n , &m ) && n>=0 && m>=0 ) ;
}
hi , why this code get tle ?
studying @ ntu csie
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

Can you use %I64d? Use %lld instead.
SRX
Learning poster
Posts: 63
Joined: Sat May 14, 2005 8:13 am
Location: Taiwan

Post by SRX »

mamun wrote:Can you use %I64d? Use %lld instead.
thanks :D
I use "%lld" and get ac now !
studying @ ntu csie
midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

Post by midra »

I use %I64d when I am on windows
and %lld for linux
so, remember always to put to the codes that you send to the online judge %lld instead of %I64d
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

midra wrote:so, remember always to put to the codes that you send to the online judge %lld instead of %I64d
To make sure you won't forget to change %I64d to %lld before submiting, you may write something like this:

Code: Select all

#ifdef ONLINE_JUDGE
  #define LLONG "%lld"
#else
  #define LLONG "%I64d"
#endif

int main(void)
{
       long long int t=7;
       printf("t=" LLONG "\n", t);
       return 0;
}
This should compile and work on both -- your windows machine and the online judge, too.
Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

Post by Quantris »

When I switched to VS .NET 2003, I discovered that %lld works (%I64d is still a valid alternative), which was nice.
shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

11038 why wa!!!!!!

Post by shakil »

please help me(I am new in acm).

Code: Select all


Cut after AC

[/b]
Last edited by shakil on Fri Apr 13, 2007 10:22 am, edited 1 time in total.
SHAKIL
Post Reply

Return to “Volume 110 (11000-11099)”