Poj 1005 Java I Think I Need a Houseboat

数学题,直接求所在点的那个半圆面积,然后直接除以50即可,另外强制转换类型为int的时候对小数部分的处理是直接去尾法,而不是四舍五入.

Java源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int col = in.nextInt();
        for(int i = 0; i < col; i++){
            float x = in.nextFloat();
            float y = in.nextFloat();
            float r = (float)Math.sqrt(x*x+y*y);
            float s = (float) (r*r*Math.PI);
            int res = (int)s/100;
            System.out.println("Property "+(i+1)+": This property will begin eroding in year "+(res+1)+".");
        }
        System.out.println("END OF OUTPUT.");
    }
}

除非注明,饮水思源博客文章均为原创,转载请以链接形式标明本文地址

本文地址: http://www.alonemonkey.com/acmpoj1005.html

本文链接:http://www.alonemonkey.com/acmpoj1005.html