10706 - Number Sequence

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

Moderator: Board moderators

Solaris
Learning poster
Posts: 99
Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:

Post by Solaris »

my AC program gives the same o/p as yours.
Where's the "Any" key?
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

I use brute force method.
But I got TLE!!
Who can give me a hint.
Thanks in advanced!
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

10706 help

Post by IRA »

I use brute force method.
But I got TLE!!
Who can give me a hint.
Thanks in advanced!
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

10706 why WA

Post by IRA »

Please help me....Why WA!?
Or give me some input data and output data....
Thanks in advance!

Code: Select all

Acc......

Code: Select all

my Input
18
8
3
80
546
23423 
65753 
2345 
45645756 
546454 
6786797 
131231 
78934124 
68904565 
123487907 
5655 
778888 
101011 
2147483647 

Code: Select all

my output
2
2
0
2
3
1
5
5
2
5
9
7
5
7
1
5
5
2 
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10706 why WA

Post by Martin Macko »

IRA wrote:Please help me....Why WA!?
Or give me some input data and output data....
Thanks in advance!
The ouputs you've posted are correct. :)
898989
Learning poster
Posts: 83
Joined: Wed Feb 01, 2006 12:59 pm
Location: (Fci-cu) Egypt
Contact:

Post by 898989 »

Salamo Aleko
This problem is not hard but need some work.Try to display the numbers in the sequence and thier digits and find any relation but you may not able to solve this problem without solving "10427 Naughty Sleepy Boys"

In problem 10706

All what we have to do is to reduce this problem input to
the number of digits in poblem 10427
And then applying its code

To do that we only remove previous digts of it
1 1

1 2
2 3

1 4
2 5
3 (6) largest possible number less than it in end

1 7
2 8
3 (9)
4 10

e.g if given input 9 all what i have to do is to remve it from
the largest possible number less than it [in end-1 of interval]
which is 6 so send to code_10427(9-6)


Let take another example : Look for the sequence 1121231234.. view it as

1 1
*********
1 2
2 3
*********
1 4
2 5
3 6
*********
1 7
2 8
3 9
4 10
*********
1 11
2 12
3 13
4 14
5 15
*********
1 16
2 17
3 18
4 19
5 20
6 21
*********
1 22
2 23
3 24
4 25
5 26
6 27
7 28
*********
1 29
2 30
3 31
4 32
5 33
6 34
7 35
8 36
*********
1 37
2 38
3 39
4 40
5 41
6 42
7 43
8 44
9 (45)
*********
1 46
2 47
3 48
4 49
5 50
6 51
7 52
8 53
9 54
10 (55) 56
//////////////////////////////////

Now assume input is (55) we know[By calculating and save in arr[32000]]

That previous interval end with 45 which is the sum of all prev digits

Now 55-45=10 send this output to code_10427(55-45) to get 10

Lastely assume it is 56 so code_10427(56-45=11)

I hope this is enough..If need more explantation or help.Just ask. :o :o
Sleep enough after death, it is the time to work.
Mostafa Saad
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

My code passed all of these testcases and still WA! why? :((
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

I got it at last. I test these samples in VC++ and it has some precision rounding. when i use log() to compute number`s length in gcc i should add 1e-8 to the result. what a silly mistake!
sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan »

Do I need to store the sum of the groups as u mentioned ?????

Thanks In Advance
898989
Learning poster
Posts: 83
Joined: Wed Feb 01, 2006 12:59 pm
Location: (Fci-cu) Egypt
Contact:

Post by 898989 »

In my program i save for efficency., i do not know if i will get tle excceed with out it or not.

Code: Select all

const int MAX = 12;
int nines [MAX]; //9,99,999,9999,99999,...
int tens  [MAX]; //1,10,100,1000,10000....
int digits[MAX]; //9,180,2700...9*[interval num of digits=i+1]*10^i
unsigned long nums[32000];	


void build_table();
int get_num_of_digits(int num);
void build_accum_digits();
void solve_with_code_10427(int num_digtit);
int getDigit(int num, int digtPos);

int main()
{
	build_accum_digits();
	build_table();

	int num, cases;

	cin>>cases;

	while(cases--)
	{
		cin>>num;
		solve_with_code_10427( get_num_of_digits(num) );
	}
	return 0;
}
I copy these pattern form my code, i do not know if it will be useful or not
I think i forget many detail of implentation.
Sleep enough after death, it is the time to work.
Mostafa Saad
sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan »

Thanks for ur reply .. The whole idea is very clear to me..... But i am still confusing in this
Now assume input is (55) we know[By calculating and save in arr[32000]]

That previous interval end with 45 which is the sum of all prev digits
How can i get the sum of the previous interval without restoring it .... and if i store them it takes a very long time ...... How can i over come it ????


Thanks in Advance
898989
Learning poster
Posts: 83
Joined: Wed Feb 01, 2006 12:59 pm
Location: (Fci-cu) Egypt
Contact:

Post by 898989 »

sorry i do not know how by nost saving
but as u see from my code these two first calls will be running on laa cases for efficeny(as i remember)
my code have good time
so it is ur implementation problem
try to find the function that take large time
and we may speak about it.
Sleep enough after death, it is the time to work.
Mostafa Saad
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude »

are nt you just spoiling his fun? to be true?
fahim
#include <smile.h>
mnafshin
New poster
Posts: 4
Joined: Sat Sep 25, 2010 4:14 pm

Re: 10706 - Number Sequence

Post by mnafshin »

Hi every body
i really need help
i write this code for this problem i checked it for about 100000 test cases in uvatoolkit.com and it work correctly but i got WA :(

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int a[60002];
int b[60002];
char s[2000000];

int len(int n)
{
return log10l(n)+1;
}

char *intTochar(int n)
{
char t[20];
int l=len(n);
t[l]=0;
int i=1;
while(n>0)
{
int x=n%10;
t[l-i]=x+'0';
i++;
n/=10;
}
return t;
}

void pre()
{
a[0]=0;
for(int i=1;i<=31500;i++)
a=a[i-1]+len(i);
for(int i=1;i<=31500;i++)
b=b[i-1]+a;
s[0]=0;
for(int i=1;i<=31500;i++)
strcat(s,intTochar(i));
}

int binSearch(int x)
{
int low = 1;
int high = 31267;
//while(b[high]<0)high--;
while(low <= high)
{
int mid = (low+high)/2;
if(b[mid]==x)return mid;
else if ( b[mid] > x)
high = mid-1;
else low = mid+1;
}
return high;
}

int main()
{
int tnum;
int n;
pre();
for(cin>>tnum;tnum--;)
{
cin >> n;
int idx = binSearch(n);
int dif = n-b[idx]-1;
if(dif==-1)
dif = n-b[idx-1]-1;
cout << s[dif] << endl;
}
}
mnafshin
New poster
Posts: 4
Joined: Sat Sep 25, 2010 4:14 pm

Re: 10706 - Number Sequence

Post by mnafshin »

i checked my code in iranian contest web site and worked correctly ???????????? but i got WA
http://sina.sharif.edu/~acmicpc/acmicpc ... probs.html
problem D

i'm confuse :evil:
Post Reply

Return to “Volume 107 (10700-10799)”