andy6804tw
8/14/2016 - 4:44 PM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2000 這題先用迴圈遞增算寬然後得出高就能利用三角形勾股定理求出對角長了

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=2000

這題先用迴圈遞增算寬然後得出高就能利用三角形勾股定理求出對角長了

import java.util.*;  
  
public class Main {  
  
    public static void main(String[] args) {  
        Scanner scn = new Scanner(System.in);  
       	int a=scn.nextInt(),b=scn.nextInt(),tot=0,i;
       	for(i=1;tot<a;i++){
       		tot+=i;
       	}
       	int w=i-1,h=a-(tot-w);
       	System.out.printf("%.6f\n",Math.sqrt(Math.pow(w*b, 2.0)+Math.pow(h*b, 2.0)));
    }
    /* 
    題目:[C_MM060-易] 疊積木
    作者:1010
    時間:西元 2016 年 8 月 */
}