F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem K. Pow2

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 163    Accepted Submission(s): 90


Problem Description
SillyDarkGK has two type of numbers:
type1. 2^x. (2, 4, 8, 16, Ą­)
type2. -(2^x). (-2, -4, -8, -16, Ą­)
He wants a new number S, for getting S, he should choose some numbers that the sum of them is S.
For example, if SillyDarkGK wants 5, he can use 2, 2, -1, -1, -1, 8 and -4 to get it. (He can use number arbitrary times.)
(S is very big, so we will give you a 01-string to describe it.)
Choosing is boring, so SillyDarkGK wants to choose numbers as fewer as possible. To increase the difficulty, SillyDarkGK canĄŻt use some special numbers.
(We will also give you two 01-string to describe what you canĄŻt use.)
itĄŻs guaranted that there is at least one way to solve it and answer wonĄŻt exceed
1e9.
 

Input
Multiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for each group, the first line have a positive integer n which describe the number of bits of S.
and on the second line there is an n-length-01-string to describe S, from low to high. On the third line there is an n-length-01-string which describe the type1 number that you canĄŻt use, from low to high, if there is a ĄŻ1ĄŻ on the x-th digit, you canĄŻt use two
to the power of x.
On the last line there is an n-length-01-string which describe the type2 number that you canĄŻt use, from low to high, if there is a ĄŻ1ĄŻ on the x-th digit, you canĄŻt use minus two to the power of x.
There is a blank line before each groups of data.
T<=1000, n<=100000, sum of n<=1000000, answer wonĄŻt exceed 1e9
 

Output
Your output should include T lines, for each line, output the answer for the corre- sponding datum.
 

Sample Input
3 6 110010 110101 011111 9 100101110 011111111 111111111 5 11111 00000 00000
 

Sample Output
3 233 2
 

Hint

for the first datum, SillyDarkGK will use 4, 16 and -1;
for the second datum, SillyDarkGK will use 1 for 233 times; for the third datum, SillyDarkGK will use 32 and -1.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:48:26, Gzip enabled