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>


  • 相关阅读:
    win10快捷键
    emmet语法
    sublime 快捷键,左菜单乱码
    Windows 10 下 MarkdownPad2 预览无法显示是怎么回事?
    html5上传图片
    mysql多表查询
    用C#创建一个窗体,在构造函数里面写代码和在from_load事件里面写代码有什么不同?
    有复选框情况下,sql拼写技巧
    C# 图片 旋转和翻转 RotateFlip
    ListView
  • 原文地址:https://www.cnblogs.com/codeyuan/p/4254431.html
Copyright © 2011-2022 走看看