10479 - The Hendrie Sequence
Moderator: Board moderators
-
- New poster
- Posts: 44
- Joined: Tue Apr 15, 2003 4:31 pm
- Location: Chittagong,Bangladesh
- Contact:
10479 - The Hendrie Sequence
Here input is 19 digit (maximum).In long double it can not handle.Can anyone tell me how it possible to take input and also handle?
I solve it but can possible for 18 digit input.
I solve it but can possible for 18 digit input.
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
Input:
Output:
Note that the last case is illegal, so if your program doesn't handle it correctly, it's no biggie.
Code: Select all
63
64
44
806856837013209088
80685
1424216473284256275
987655432
9223372036854775807
9223372036854775808
0
Code: Select all
0
6
3
16
0
1
4
0
63
Yup, that's what I did as well (and I have a friend who solved it this way too), though I computed the first numbers by "hand" (or actually, by cut'n'paste).
Other ways... I don' know, maybe some lisp guru could do some funky lazy evaluation stuff.![;)](./images/smilies/icon_wink.gif)
It doesn't seem very probable though, I think it's hard to devise a general method.
Other ways... I don' know, maybe some lisp guru could do some funky lazy evaluation stuff.
![;)](./images/smilies/icon_wink.gif)
It doesn't seem very probable though, I think it's hard to devise a general method.
I got WA with this problem. Please help me to find my bug.
[cpp]#include <stdio.h>
#include <math.h>
int depth, ans;
long long int serial, current;
int recurse(int n, int d)
{
int i, tempDepth;
long long int tempCurrent;
if(d==depth)
{
if(serial==current+1)
{
ans = n;
return 1;
}
else
return 0;
}
for(i=0; i<n; i++)
{
tempDepth = depth - d - 1;
if(tempDepth > 0)
tempCurrent = current + (long long int) (pow(2, tempDepth-1));
else
tempCurrent = current + 1;
if(serial <= tempCurrent)
{
if(recurse(0, d+1))
return 1;
}
else
current = tempCurrent;
}
if(recurse(n+1, d+1))
return 1;
return 0;
}
int main()
{
long long int n;
double m;
while(1==scanf("%lli", &n) && n)
{
if(n==1)
{
printf("0\n");
continue;
}
m = ceil(log((double)n)/ log(2.0) - 0.000001);
depth = (int) m;
serial = n - (long long int)pow(2.0, m-1);
current = 0;
recurse(0, 0);
printf("%d\n", ans);
}
return 0;
}[/cpp]
[cpp]#include <stdio.h>
#include <math.h>
int depth, ans;
long long int serial, current;
int recurse(int n, int d)
{
int i, tempDepth;
long long int tempCurrent;
if(d==depth)
{
if(serial==current+1)
{
ans = n;
return 1;
}
else
return 0;
}
for(i=0; i<n; i++)
{
tempDepth = depth - d - 1;
if(tempDepth > 0)
tempCurrent = current + (long long int) (pow(2, tempDepth-1));
else
tempCurrent = current + 1;
if(serial <= tempCurrent)
{
if(recurse(0, d+1))
return 1;
}
else
current = tempCurrent;
}
if(recurse(n+1, d+1))
return 1;
return 0;
}
int main()
{
long long int n;
double m;
while(1==scanf("%lli", &n) && n)
{
if(n==1)
{
printf("0\n");
continue;
}
m = ceil(log((double)n)/ log(2.0) - 0.000001);
depth = (int) m;
serial = n - (long long int)pow(2.0, m-1);
current = 0;
recurse(0, 0);
printf("%d\n", ans);
}
return 0;
}[/cpp]
I think the input is not a valid one.
Code: Select all
Each test case consists of a single line containing the integer n ( 0 < n < 2^63)
Last edited by Subeen on Sat Aug 14, 2004 5:40 pm, edited 1 time in total.
I don't understand the problem...
The Hendrie Sequence ``H" is a self-describing sequence defined as follows:
H(1) = 0
If we expand every number x in H to a subsequence containing x 0's followed by the number x + 1, the resulting sequence is still H (without its first element).
Thus, the first few elements of H are:
0,1,0,2,1,0,0,3,0,2,1,1,0,0,0,4,1,0,0,3,0,...
Can anyone explain why the sequence like tat?
regards,
stephanus
The Hendrie Sequence ``H" is a self-describing sequence defined as follows:
H(1) = 0
If we expand every number x in H to a subsequence containing x 0's followed by the number x + 1, the resulting sequence is still H (without its first element).
Thus, the first few elements of H are:
0,1,0,2,1,0,0,3,0,2,1,1,0,0,0,4,1,0,0,3,0,...
Can anyone explain why the sequence like tat?
regards,
stephanus
http://www.harvestsoft.net
Stephanus
Stephanus
tep, see the tree below:
now start traversing each level left to right
hope it helps...
but I got WA with my code
some one please post some test cases.
Code: Select all
0
|
1
/ \
0 2
/ / | \
1 0 0 3
hope it helps...
but I got WA with my code
![:(](./images/smilies/icon_frown.gif)
10479 - The Hendrie Sequence WA
Get AC
Last edited by hpjhc on Mon Feb 24, 2014 8:40 am, edited 5 times in total.
Re: 10479 - The Hendrie Sequence WA
Have you even looked at this thread?
http://online-judge.uva.es/board/viewto ... 479#p10598
If you expect people to look at your code, the least you can do is make your code readable by using the code tags.
http://online-judge.uva.es/board/viewto ... 479#p10598
If you expect people to look at your code, the least you can do is make your code readable by using the code tags.