2014 ACM/ICPC Asia Regional Shanghai Online 1009
2014-09-27 18:36
387 查看
Divided Land
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As the mayor, you must segment the land into multiple squares of equal size for
the villagers. What are required is there must be no any waste and each single segmented square land has as large area as possible. The width of the segmented square land is also binary.
Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve. Each case contains two binary number represents the length L and the width W of given land. (0 < L, W ≤ 21000)
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then one number means the largest width of land that can be divided from input data. And it will be show in binary. Do not have any useless number
or space.
Sample Input
3
10 100
100 110
10010 1100
Sample Output
Case #1: 10
Case #2: 10
Case #3: 110
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As the mayor, you must segment the land into multiple squares of equal size for
the villagers. What are required is there must be no any waste and each single segmented square land has as large area as possible. The width of the segmented square land is also binary.
Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve. Each case contains two binary number represents the length L and the width W of given land. (0 < L, W ≤ 21000)
Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then one number means the largest width of land that can be divided from input data. And it will be show in binary. Do not have any useless number
or space.
Sample Input
3
10 100
100 110
10010 1100
Sample Output
Case #1: 10
Case #2: 10
Case #3: 110
<span style="color:#000099;">import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { int t; Scanner s = new Scanner(System.in); t=s.nextInt(); for(int j=1;j<=t;j++){ String s1 = null,s2=null; s1= s.next();s2=s.next(); BigInteger num1 =new BigInteger("0"); BigInteger num2= new BigInteger("0"); BigInteger sum =new BigInteger("1"); BigInteger flag =new BigInteger("2"); for(int i=s1.length()-1; i>=0; i--) { if(s1.charAt(i)=='1'){ num1=num1.add(sum);} sum=sum.multiply(flag); } BigInteger sum1 =new BigInteger("1"); for(int i=s2.length()-1; i>=0; i--) { if(s2.charAt(i)=='1'){ num2=num2.add(sum1);} sum1=sum1.multiply(flag); } BigInteger ans = num1.gcd(num2); String res1=""; res1=ans.toString(2); System.out.println("Case #"+j+": "+res1);} } }</span>
相关文章推荐
- 2014 ACM/ICPC Asia Regional Shanghai Online 1009
- HDU 5045 Contest 期望+状压dp 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5047 Sawtooth 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU 5047 Sawtooth 规律+ C++大数模拟 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5052 Yaoge’s maximum profit 树链剖分 2014 ACM/ICPC Asia Regional Shanghai Online
- 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU Tree LCA 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU 5046 Airport DLX 2014 ACM/ICPC Asia Regional Shanghai Online
- The 2014 ACMICPC Asia Regional Shanghai Online
- hdu 5050 Divided Land 大数求GCD 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU 5052 Yaoge’s maximum profit 裸树链剖分 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU5053-the Sum of Cube-2014 ACM/ICPC Asia Regional Shanghai Online(水题求立方和)
- hdu 5053 the Sum of Cube 水题 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5047 Sawtooth 折线分割平面 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5047 Sawtooth 2014 ACM/ICPC Asia Regional Shanghai Online 数学
- hdu 5050 Divided Land 大数求GCD 2014 ACM/ICPC Asia Regional Shanghai Online
- hdu 5045 - Contest(2014 ACM/ICPC Asia Regional Shanghai Online )概率dp
- 2014 ACM/ICPC Asia Regional Shanghai Online
- 2014 ACM/ICPC Asia Regional Shanghai Online 1006 Sawtooth