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>


  • 相关阅读:
    SharePoint Timer Job
    内容查询部件 之 简单美化
    SharePoint list Search
    Sharepoint 2010 Content Search Webpart
    如何添加Features,处理自己的程序
    SharePoint 读取 UserMulti 类型的字段
    SharePoint 账号
    配制备用访问映射
    项目管理汇总
    Altium Desgner软件,PCB设计中铺铜的作用
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254431.html
Copyright © 2011-2022 走看看