`
贝壳水母
  • 浏览: 146251 次
  • 性别: Icon_minigender_1
  • 来自: 广州中低收入人群
社区版块
存档分类
最新评论

Problem1005

    博客分类:
  • POJ
阅读更多
/**
 * Description
 * Fred Mapper is considering purchasing some land in Louisiana to build his house on. 
 * In the process of investigating the land, 
 * he learned that the state of Louisiana is actually shrinking by 50 square miles each year, 
 * due to erosion caused by the Mississippi River. 
 * Since Fred is hoping to live in this house the rest of his life, 
 * he needs to know if his land is going to be lost to erosion. 
 * After doing more research, 
 * Fred has learned that the land that is being lost forms a semicircle. 
 * This semicircle is part of a circle centered at (0,0), 
 * with the line that bisects the circle being the X axis. 
 * Locations below the X axis are in the water. 
 * The semicircle has an area of 0 at the beginning of year 1. 
 * (Semicircle illustrated in the Figure.) 
 * 
 * Input
 * The first line of input will be a positive integer indicating how many data sets will be included (N). 
 * Each of the next N lines will contain the X and Y Cartesian coordinates of the land Fred is considering. 
 * These will be floating point numbers measured in miles. 
 * The Y coordinate will be non-negative. (0,0) will not be given.
 * 
 * Output
 * For each data set, a single line of output should appear. 
 * This line should take the form of: “Property N: This property will begin eroding in year Z.” 
 * Where N is the data set (counting from 1), 
 * and Z is the first year (start from 1) this property will be within the semicircle AT THE END OF YEAR Z. 
 * Z must be an integer. After the last data set, this should print out “END OF OUTPUT.”
 * 
 * Sample Input
 * 2
 * 1.0 1.0
 * 25.0 0.0
 * 
 * Sample Output
 * Property 1: This property will begin eroding in year 1.
 * Property 2: This property will begin eroding in year 20.
 * END OF OUTPUT.
 * 
 * Hint
 * 1.No property will appear exactly on the semicircle boundary: 
 * it will either be inside or outside. 
 * 2.This problem will be judged automatically. 
 * Your answer must match exactly, including the capitalization, punctuation, and white-space. 
 * This includes the periods at the ends of the lines. 
 * 3.All locations are given in miles.
 */

package acm;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Problem1005 {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				String s = br.readLine();
				StringTokenizer stk = new StringTokenizer(s);
				double d1 = Double.parseDouble(stk.nextToken());
				double d2 = Double.parseDouble(stk.nextToken());
				double wantKnow = d1*d1+d2*d2;
				double square = 50;
				int count = 1;
				//圆的边长平方-坐标所在矩形的斜边长的平方,若大于等于零则在该情况下已被侵蚀
				while(square/Math.PI*2-wantKnow<0){
					count++;
					square+=50;
				}
				System.out.println("Property "+(i+1)+": This property will begin eroding in year "+count+".");
			}
			System.out.println("END OF OUTPUT.");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}



题目:原题有个图的,容易理解多了,=_= 我懒,就将就着啦,说,有个人,住的是岛好像,岛的面积呢,每年会因为河流的冲刷,导致面积减少50平方mile,冲刷掉的地方呢,是一个半圆来的,就是以原点为圆心,x轴以上的部分,一开始的时候,是完整的,然后第一年就以半圆的形状扩散出去50平方mile,第二年在这个基础上再扩散50,但形状是保持半圆的,input部分给的是一个坐标,output需要给出这个坐标在哪一年会被侵蚀掉

我的理解:计算每一年最后形成的半圆的半径,如果坐标值对应的矩形的斜边大于该半径,既是还不会侵蚀到啦,就再接着算下一年,直到小于等于半径

PS:到此,我的第一阶段做的题目就结束啦……
接下去还能不能坚持做练习,就……
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics