日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > HDU 5050 Divided Land(最大公約數Java)

HDU 5050 Divided Land(最大公約數Java)

來源:程序員人生   發布時間:2014-10-12 18:52:16 閱讀次數:2279次

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=5050


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
 

Source
2014 ACM/ICPC Asia Regional Shanghai Online

PS:

思路很簡單,就是把輸入的二進制長和寬轉化為十進制求一個GCD然后在轉換為二進制輸出即可,不過由于數據過大,需要用Java來實現,這里貼一發隊友敲的Java;


代碼如下:

import java.math.*; import java.util.Scanner; public class Main{ public static BigInteger gcd(BigInteger a,BigInteger b) { if(b.equals(BigInteger.ZERO)) return a; return gcd(b,a.mod(b)); } public static void main(String[] args) { Scanner input = new Scanner(System.in); int t,i,j; String s=null; char str[]; BigInteger a,b; t=input.nextInt(); for(i=1;i<=t;i++) { a=input.nextBigInteger(2); b=input.nextBigInteger(2); a=gcd(a,b); System.out.println("Case #"+i+": "+a.toString(2)); } } }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久99精品久久久久久噜噜 | 欧美在线一区二区三区四区 | 日本一区二区不卡视频 | 欧美日韩在线精品 | 日韩在线中文字幕 | 国产午夜精品视频 | 久久精品国产一区二区三区 | 欧美日产国产成人免费图片 | 91精品国产三级a在线观看 | 欧美日本韩国一区二区三区 | 日韩精品一区二区三区在线播放 | 丁香五月网久久综合 | 自拍偷拍一区二区三区 | 国产原创视频 | 亚洲情乱| 国产高清在线看 | 久久久久毛片 | jizz在线观看| 久久精品国产99国产 | 国产精品成人一区二区三区夜夜夜 | 日韩精品中文字幕一区二区 | 亚洲一区二区高潮无套美女 | 午夜欧美一区二区三区在线播放 | 久久精品99国产精品 | 老司机成人网 | 色姑娘色综合 | 国产在线观看一区二区三区 | 国产福利在线 | 免费成人av在线 | 亚洲经典三级 | 亚洲一区二区av | 国产一区二区三区欧美 | 9191国产精品 | 久久久一区二区三区 | 婷婷在线综合 | 久草新免费 | 国产一区自拍视频 | 成人性视频免费网站 | 国产一级片网 | 中文字幕一区二区三区精彩视频 | 欧美亚洲一区二区三区四区 |