10705 - The Fun Number System

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

Post Reply
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

10705 - The Fun Number System

Post by htl »

Is there a good algo to solve it? I think brute force would take much time.
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

yes there is a very good algo.
think like they were just ordinary binary numbers.
just do a small modification for the negative ones.
bye
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan

Post by htl »

You mean the posibits won't be modified whether we use ordinary or the 'Fun' system? Hmmm.... Let me take some time to figure out :roll:
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer »

Hint: think of the technique of "excess code".
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

hi,
i solved this problem. but i don't know what is "excess code". Can you give me some links to that? I'd like to learn that technique too.
bye
abi
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer »

Oops.. It's actually NOT a programming technique. It's just a way to store integers in computers......
(Sorry if I've caused confusion :oops:)

Check this out: http://library.thinkquest.org/26532/inside/coding/.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
abductor
New poster
Posts: 8
Joined: Sat Jan 18, 2003 6:43 pm
Location: Canada

Post by abductor »

can anyone give me some test cases with answers for the problem. thanks
hiloshi
New poster
Posts: 20
Joined: Fri Aug 27, 2004 8:15 am
Location: Kanagawa, Japan

Post by hiloshi »

hi.
I got ACCEPT, and I'll give you test data.

here is input:

Code: Select all

36
4
ppnn
10
4
nnpp
-10
4
pppp
10
4
ppnn
6
1
p
1
9
pnppnnnnn
332
11
pppnppnnnnn
332
3
ppp
0
2
nn
-2
9
ppppppppn
255
20
pppnnppnnnnpppnpnppp
894632
1
n
0
1
p
0
1
p
1
1
n
-1
3
ppp
4
4
pppp
15
3
pnp
-1
3
pnp
3
50
pnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
1
50
pnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
-1
50
nppppppppppppppppppppppppppppppppppppppppppppppppp
-1
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
3254335264364654723
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
-980195823579238788
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
4363049762604363426
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
-1351135325723452455
4
pppp
16
4
ppnn
-10
3
pnp 
6 
4
nnnn
10
1
n
1
8
nppnnnnn
332
2
nn
2
4
pppn
15
2
pp
4
1
n
1
And my output

Code: Select all

1110
1110
1010
1010
1
101110100
00101110100
000
10
100000001
11101101101011111000
0
0
1
1
100
1111
011
111
11111111111111111111111111111111111111111111111111
00000000000000000000000000000000000000000000000001
11111111111111111111111111111111111111111111111111
0011010101010111101110001101001001011101100001010111000010000111
0000111001101011101001010110101110000101010001001110111010001100
0100010110110100101010101110010010011101011011101010111011100110
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Good luck!
Last edited by hiloshi on Sun Sep 26, 2004 12:04 pm, edited 1 time in total.
I hope you can understand my poor English.
abductor
New poster
Posts: 8
Joined: Sat Jan 18, 2003 6:43 pm
Location: Canada

Post by abductor »

thanks a lot
krijger
New poster
Posts: 39
Joined: Wed Jul 21, 2004 12:35 am

Post by krijger »

Do you guys all handle this correctly?

Code: Select all

Input:
2
64
nppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
-9223372036854775808
64
nppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
9223372036854775807

Code: Select all

Output:
1000000000000000000000000000000000000000000000000000000000000000
0111111111111111111111111111111111111111111111111111111111111111
It gave me some problems because (n+1)/2 or (n-1)/2 could give overflows. I used 'n/2+(n%2-1)/2' and 'n/2+(n%2+1)/2'.
Anybody else had problems with this? And is there a nicer way to do those calculations?
Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

Post by Eduard »

I solve this problem without using such things.
I just use my proof that if we have K and some string of 'p'-s and 'n'-s than the maximum number(max) which we can give minus minimum number(min) =2^k-1.And all numbers between min and max we can give.
Last edited by Eduard on Fri Sep 03, 2004 1:23 pm, edited 1 time in total.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
abishek
Experienced poster
Posts: 131
Joined: Mon Dec 15, 2003 5:41 am

Post by abishek »

hi kriger,
i also first thought of those problems.
i handle them like this
n>>1; if the bit is a posibit
n>>1; n++; if the bit is a negabit
this will avoid all overflows
bye
abi
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »

I didn't understand the algorithm or discussions. Excess code can help here. how? Please describe the algorithm you used to solve the problem. :oops:
"Everything should be made simple, but not always simpler"
kisow
New poster
Posts: 3
Joined: Fri Jul 11, 2003 8:46 am
Contact:

.

Post by kisow »

hi hiloshi

one test data is not correct.

Code: Select all

64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
-1351135325723452455
4

Code: Select all

1111010101000001110011011111010010001111110010111001110000101001
The weight of most significant negabit (1ULL << 59)
is 576460752303423488. So, it's "Impossible".

hiloshi wrote:hi.
I got ACCEPT, and I'll give you test data.

here is input:

Code: Select all

36
4
ppnn
10
4
nnpp
-10
4
pppp
10
4
ppnn
6
1
p
1
9
pnppnnnnn
332
11
pppnppnnnnn
332
3
ppp
0
2
nn
-2
9
ppppppppn
255
20
pppnnppnnnnpppnpnppp
894632
1
n
0
1
p
0
1
p
1
1
n
-1
3
ppp
4
4
pppp
15
3
pnp
-1
3
pnp
3
50
pnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
1
50
pnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
-1
50
nppppppppppppppppppppppppppppppppppppppppppppppppp
-1
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
3254335264364654723
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
-980195823579238788
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
4363049762604363426
64
ppppnnnpnppnpnnnppppppppppnnnpnpppppnnnpnppnpnnnppppppppppnnnpnp
-1351135325723452455
4
pppp
16
4
ppnn
-10
3
pnp 
6 
4
nnnn
10
1
n
1
8
nppnnnnn
332
2
nn
2
4
pppn
15
2
pp
4
1
n
1
And my output

Code: Select all

1110
1110
1010
1010
1
101110100
00101110100
000
10
100000001
11101101101011111000
0
0
1
1
100
1111
011
111
11111111111111111111111111111111111111111111111111
00000000000000000000000000000000000000000000000001
11111111111111111111111111111111111111111111111111
0011010101010111101110001101001001011101100001010111000010000111
0000111001101011101001010110101110000101010001001110111010001100
0100010110110100101010101110010010011101011011101010111011100110
1111010101000001110011011111010010001111110010111001110000101001
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Good luck!
[/code]
hiloshi
New poster
Posts: 20
Joined: Fri Aug 27, 2004 8:15 am
Location: Kanagawa, Japan

sorry...

Post by hiloshi »

hi kisow.

I edit my replay and fix my mistake.
Thanks for your sharp shooting.
I hope you can understand my poor English.
Post Reply

Return to “Volume 107 (10700-10799)”