10427  Naughty Sleepy Boys
Moderator: Board moderators
10427  Naughty Sleepy Boys
I am getting WA.
Could some one give me some critical test cases.
Could some one give me some critical test cases.

 Guru
 Posts: 647
 Joined: Wed Jun 26, 2002 10:12 pm
 Location: Hong Kong and New York City
 Contact:
Sample:
Results:
Code: Select all
3
9
10
11
10000
50000
1000000000
5135136
351357
88456345
34135141
513341
13516167
6252345
767657
613566
5768678
63453
253478
95465462
513513511
5151356786
875673562
Code: Select all
3
9
1
0
7
1
7
4
4
1
7
0
2
0
4
0
6
1
1
2
0
5
6

 Experienced poster
 Posts: 151
 Joined: Wed Aug 21, 2002 12:07 am
 Location: Seoul, Korea
 Contact:
for 10427..
I think you don't need any "special" approaches to solve this problem.
Try analyzing it like this:
For numbers in range 1 ~ 9 (inclusive), there are 9 such numbers, each containing 1 digits.
For numbers in range 10 ~ 99 , there are 90 such numbers, each containing 2 digits.
For numbers in range 100 ~ 999 , there are 900 such numbers, each containing 3 digits.
Now you can easily come to
For numbers in range 10^(k1) ~ 10^k  1, there are 9 * 10^(k1) such numbers, each containing k digits.. (If you try it, you'll find out each of the numbers in the resulting sequence will not be that big, so you don't need any longint operations.)
So for given n, you can easily calculate which digit of which number does it point to.
Good luck =)
[edit] corrected my mistake
Try analyzing it like this:
For numbers in range 1 ~ 9 (inclusive), there are 9 such numbers, each containing 1 digits.
For numbers in range 10 ~ 99 , there are 90 such numbers, each containing 2 digits.
For numbers in range 100 ~ 999 , there are 900 such numbers, each containing 3 digits.
Now you can easily come to
For numbers in range 10^(k1) ~ 10^k  1, there are 9 * 10^(k1) such numbers, each containing k digits.. (If you try it, you'll find out each of the numbers in the resulting sequence will not be that big, so you don't need any longint operations.)
So for given n, you can easily calculate which digit of which number does it point to.
Good luck =)
[edit] corrected my mistake
JongMan @ Yonsei
I got WA....
I've tested again my code and it's doing just fine until the input <=10000000 coz there's no output generated.....
can you help me with this problem?
here are my code :
[c]
#include<stdio.h>
#include<stdio.h>
int seek(long int n);
int main()
{ long int a;
scanf("%li",&a);
printf("%d",seek(a));
return 1;
}
int seek(long int n)
{ long int i=0,j,k=0;
while(k<n)
{ i+=1;
if(i<10)
{ j=(i);
k+=1;
if(k>=n) break;
}
else if(i<100)
{ j=(i/10);
k+=1;
if(k>=n) break;
j=(i%10);
k+=1;
if(k>=n) break;
}
else if(i<1000)
{ j=(i/100);
k+=1;
if(k>=n) break;
j=((i%100)/10);
k+=1;
if(k>=n) break;
j=((i%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<10000)
{ j=(i/1000);
k+=1;
if(k>=n) break;
j=((i%1000)/100);
k+=1;
if(k>=n) break;
j=(((i%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((i%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<100000)
{ j=(i/10000);
k+=1;
if(k>=n) break;
j=((i%10000)/1000);
k+=1;
if(k>=n) break;
j=(((i%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=((((i%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=((((i%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<1000000)
{ j=(i/100000);
k+=1;
if(k>=n) break;
j=((i%100000)/10000);
k+=1;
if(k>=n) break;
j=(((i%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=((((i%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=(((((i%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((((i%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<10000000)
{ j=(i/1000000);
k+=1;
if(k>=n) break;
j=((i%1000000)/100000);
k+=1;
if(k>=n) break;
j=(((i%1000000)%100000)/10000);
k+=1;
if(k>=n) break;
j=((((i%1000000)%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=(((((i%1000000)%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=((((((i%1000000)%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=((((((i%1000000)%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<100000000)
{ j=(i/10000000);
k+=1;
if(k>=n) break;
j=((i%10000000)/1000000);
k+=1;
if(k>=n) break;
j=(((i%10000000)%1000000)/100000);
k+=1;
if(k>=n) break;
j=((((i%10000000)%1000000)%100000)/10000);
k+=1;
if(k>=n) break;
j=(((((i%10000000)%1000000)%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=((((((i%10000000)%1000000)%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=(((((((i%10000000)%1000000)%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((((((i%10000000)%1000000)%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
}
return j;
}
[/c]
I've tested again my code and it's doing just fine until the input <=10000000 coz there's no output generated.....
can you help me with this problem?
here are my code :
[c]
#include<stdio.h>
#include<stdio.h>
int seek(long int n);
int main()
{ long int a;
scanf("%li",&a);
printf("%d",seek(a));
return 1;
}
int seek(long int n)
{ long int i=0,j,k=0;
while(k<n)
{ i+=1;
if(i<10)
{ j=(i);
k+=1;
if(k>=n) break;
}
else if(i<100)
{ j=(i/10);
k+=1;
if(k>=n) break;
j=(i%10);
k+=1;
if(k>=n) break;
}
else if(i<1000)
{ j=(i/100);
k+=1;
if(k>=n) break;
j=((i%100)/10);
k+=1;
if(k>=n) break;
j=((i%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<10000)
{ j=(i/1000);
k+=1;
if(k>=n) break;
j=((i%1000)/100);
k+=1;
if(k>=n) break;
j=(((i%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((i%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<100000)
{ j=(i/10000);
k+=1;
if(k>=n) break;
j=((i%10000)/1000);
k+=1;
if(k>=n) break;
j=(((i%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=((((i%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=((((i%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<1000000)
{ j=(i/100000);
k+=1;
if(k>=n) break;
j=((i%100000)/10000);
k+=1;
if(k>=n) break;
j=(((i%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=((((i%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=(((((i%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((((i%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<10000000)
{ j=(i/1000000);
k+=1;
if(k>=n) break;
j=((i%1000000)/100000);
k+=1;
if(k>=n) break;
j=(((i%1000000)%100000)/10000);
k+=1;
if(k>=n) break;
j=((((i%1000000)%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=(((((i%1000000)%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=((((((i%1000000)%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=((((((i%1000000)%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
else if(i<100000000)
{ j=(i/10000000);
k+=1;
if(k>=n) break;
j=((i%10000000)/1000000);
k+=1;
if(k>=n) break;
j=(((i%10000000)%1000000)/100000);
k+=1;
if(k>=n) break;
j=((((i%10000000)%1000000)%100000)/10000);
k+=1;
if(k>=n) break;
j=(((((i%10000000)%1000000)%100000)%10000)/1000);
k+=1;
if(k>=n) break;
j=((((((i%10000000)%1000000)%100000)%10000)%1000)/100);
k+=1;
if(k>=n) break;
j=(((((((i%10000000)%1000000)%100000)%10000)%1000)%100)/10);
k+=1;
if(k>=n) break;
j=(((((((i%10000000)%1000000)%100000)%10000)%1000)%100)%10);
k+=1;
if(k>=n) break;
}
}
return j;
}
[/c]

 New poster
 Posts: 1
 Joined: Thu Jun 05, 2003 2:12 pm
 Contact:
I'm sad, I use 3 algortym to solve this problem but all failed. I iuse algorythm like R.Z. BUt even though the program outp[ut coorect, but judge resu;lt is, "TIME LIMIT EXEEDED!" Hixs.....
I also created the new one.. like this... maybe I made a mistakes. But whete? Can U help me?
#include <stdio.h>
void main()
{
unsigned long int x,xx,input,ctr=0,ctr2=0;
char str[10],flag='t';
scanf("%lu",&input);
for(x=1;x<=input;x++)
{
sprintf(str,"%lu",x);
for(xx=0;str[xx];xx++)
{
ctr++;
ctr2++;
if(ctr==input) { flag='f'; break; }
}
if(flag=='f') break;
else ctr2=0;
}
printf("hasil %c \n",str[ctr21]);
}
I also created the new one.. like this... maybe I made a mistakes. But whete? Can U help me?
#include <stdio.h>
void main()
{
unsigned long int x,xx,input,ctr=0,ctr2=0;
char str[10],flag='t';
scanf("%lu",&input);
for(x=1;x<=input;x++)
{
sprintf(str,"%lu",x);
for(xx=0;str[xx];xx++)
{
ctr++;
ctr2++;
if(ctr==input) { flag='f'; break; }
}
if(flag=='f') break;
else ctr2=0;
}
printf("hasil %c \n",str[ctr21]);
}
help meeee
you can not solve 10427 in that way. it will definitely get "tle".
u should follow Whinii F.'s given method. u can count the total number of digit by the following method:
with the total number between the range. i.e total number of digits between 10~99 is 180. so you should calculate total number of digit
as long as it does not exceed the given value then you can easily find the number in which the nth digit will appear.
u should follow Whinii F.'s given method. u can count the total number of digit by the following method:
then you can count the digit number by just multiplying the number of digitFor numbers in range 1 ~ 9 (inclusive), there are 9 such numbers, each containing 1 digits.
For numbers in range 10 ~ 99 , there are 90 such numbers, each containing 2 digits.
For numbers in range 100 ~ 999 , there are 900 such numbers, each containing 3 digits.
with the total number between the range. i.e total number of digits between 10~99 is 180. so you should calculate total number of digit
as long as it does not exceed the given value then you can easily find the number in which the nth digit will appear.
zubairCUET old sailor
output limit?!
I found an easy way to calculate the answer...
BUTTTT...
[cpp]if (cifra <10 )printf("%d\n",cifra);[/cpp]
cifra is the digit you are looking for.
I can include my code but I don't know if that's legal?!
byebyes
BUTTTT...
I don't understand WHY because I include this sentence:Your program output is greater (4236247 bytes) than the maximum allowed for any problem by this judge (4194304 bytes).
You must interprete this as a Wrong Answer (in fact, is wrong!).
By some reason your program is writing an unlimited output.
[cpp]if (cifra <10 )printf("%d\n",cifra);[/cpp]
cifra is the digit you are looking for.
I can include my code but I don't know if that's legal?!
byebyes
maru 3.1415926
dont kill me plz
maybe in windows it's different (?) because I have no problem with this:
[cpp]long int n;
scanf("%d",&n);[/cpp]
thank you.
[cpp]long int n;
scanf("%d",&n);[/cpp]
thank you.
maru 3.1415926

 Learning poster
 Posts: 82
 Joined: Thu Oct 10, 2002 1:15 pm
 Location: St. Johns, Canada
 Contact:
Zubire wrote
from 1 to 10 the number are one digit
from 11 to 190 the number are two digit
and so on...
then find the number.
to do this, just make a simple calculation.
M H Rasel
CUET Old Sailor
To solve this problem, first you need to find the number which digit will be print. to do this do some sample calculation i.e.,you can count the digit number by just multiplying the number of digit
with the total number between the range. i.e total number of digits between 10~99 is 180. so you should calculate total number of digit
as long as it does not exceed the given value then you can easily find the number in which the nth digit will appear
from 1 to 10 the number are one digit
from 11 to 190 the number are two digit
and so on...
then find the number.
to do this, just make a simple calculation.
M H Rasel
CUET Old Sailor

 Learning poster
 Posts: 82
 Joined: Thu Oct 10, 2002 1:15 pm
 Location: St. Johns, Canada
 Contact:
Zubire wrote
from 1 to 10 the number are one digit
from 11 to 190 the number are two digit
and so on...
then find the number.
to do this, just make a simple calculation.
M H Rasel
CUET Old Sailor
To solve this problem, first you need to find the number which digit will be print. to do this do some sample calculation i.e.,you can count the digit number by just multiplying the number of digit
with the total number between the range. i.e total number of digits between 10~99 is 180. so you should calculate total number of digit
as long as it does not exceed the given value then you can easily find the number in which the nth digit will appear
from 1 to 10 the number are one digit
from 11 to 190 the number are two digit
and so on...
then find the number.
to do this, just make a simple calculation.
M H Rasel
CUET Old Sailor