zoukankan      html  css  js  c++  java
  • 2014 ACM/ICPC Asia Regional Shanghai Online 1009

    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

    <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>


  • 相关阅读:
    python之面向对象
    Python常用模块(logging&re&时间&random&os&sys&shutil&序列化&configparser&&hashlib)
    Python之模块与包
    2.1 、寻找元素 (重要的选择器和筛选器)
    4、循环语句 和 异常处理
    7、其他知识点
    2、函数 面向对象
    3、数据类型
    1、初识JavaScript
    2、css
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254431.html
Copyright © 2011-2022 走看看