POJ 1005 I Think I Need a Houseboat
2015-08-09 15:36
399 查看
http://poj.org/problem?id=1005
I Think I Need a Houseboat
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
Sample 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.
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int i,n,ans;
double x,y,sum;
n=input.nextInt();
for(i=1;i<=n;i++)
{
x=input.nextDouble();
y=input.nextDouble();
ans=0;
sum=0;
double r=Math.sqrt(x*x+y*y);
do
{
ans+=1;
sum+=50.0;
}while(!(sum>r*r*Math.PI/2.0));
System.out.println("Property "+i+": This property will begin eroding in year "+ans+".");
}
System.out.println("END OF OUTPUT.");
}
}
http://poj.org/problem?id=1005
I Think I Need a Houseboat
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 92854 | Accepted: 40388 |
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.
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int i,n,ans;
double x,y,sum;
n=input.nextInt();
for(i=1;i<=n;i++)
{
x=input.nextDouble();
y=input.nextDouble();
ans=0;
sum=0;
double r=Math.sqrt(x*x+y*y);
do
{
ans+=1;
sum+=50.0;
}while(!(sum>r*r*Math.PI/2.0));
System.out.println("Property "+i+": This property will begin eroding in year "+ans+".");
}
System.out.println("END OF OUTPUT.");
}
}
相关文章推荐
- 设计模式之——单例模式(Singleton)的实现、优缺点和常见应用场景
- ERROR! MySQL is running but PID file could not be found
- B树、B-树、B+树、B*树的区别
- Product of Array Exclude Itself
- 语言的艺术3
- hdu1176 免费馅饼 ( 数塔(DP))
- LeetCode之Binary Tree Level Order Traversal II
- HDOJ1232 畅通工程(并查集)
- ActionScript 3.0 学习(四) AS3显示对象的几个基本属性,ButtonMode,DropTarget,hitArea以及ScaleX,ScaleY,ScrollRect
- 音乐录像带之如何使用静态的makeEvent()方法
- 第九章 动态规划初步
- 《python标准库》--subprocess <一、运行外部命令>
- hdu 5366 (bc #50 1003) The mook jong
- HDU 3836 Equivalent Sets
- android studio
- 同时查找数组中最大和最小值
- kd树的构建以及搜索
- 第22章 声音与音乐(3)
- 重要的书籍看三遍(从看书开始写起)
- 怎么计算数组中实际元素的个数?