每天一道算法_6_I Think I Need a Houseboat

今天的题目是I Think I Need a Houseboat如下:DescriptionFred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the st

大家好,又见面了,我是全栈君。

今天的题目是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.)  

每天一道算法_6_I Think I Need a Houseboat

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.ArrayList;
import java.util.List;
import java.util.Scanner;


public class IThinkINeedaHouseboat {
	public static void main(String args[]){
		double PI = 3.1415926;
		int year = 1;
		float area = 0;
		int year_count = 0;
		Scanner in = new Scanner(System.in);
		int all = in.nextInt();
		int count = all * 2;
		List<Float> list = new ArrayList<Float>();
		while(count > 0){
			count--;
			list.add(in.nextFloat());
		}
		for(int i = 0; i<list.size(); i = i + 2){
			year_count ++;
			area = (float) (PI*(list.get(i) * list.get(i) + list.get(i + 1) * list.get(i + 1))/2);
			for(year = 1; year * 50 < area; year ++){
				
			}
			System.out.println("Property "+ year_count + ": This property will begin eroding in year " + year + ".");
		}
		System.out.println("END OF OUTPUT.");
	}
}

 

作者:jason0539

微博:http://weibo.com/2553717707

博客:http://blog.csdn.net/jason0539(转载请说明出处)

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/121384.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • vb.net 学习「建议收藏」

    vb.net 学习「建议收藏」一、vb.net是什么vb:即VisualBasic.net:是一个开发平台,在这个平台上可以开发多种语言。bcl:我的理解就是类的定义clr:我的理解就是类的使用。作用:(相当于java虚拟机,内存管理,垃圾清理)注:因为百度上说的都太宏观了,目前还是刚刚接触这个,是从名字上去理解,有其他见解可以留言或后面我有不同感悟再改二、vb.net有什么用目前我接触到:控制台程序 窗体程序 webservice三、怎么用说一个可能很多人忽略或只有我忽略了一下吧.

    2022年6月21日
    20
  • latex插入图片

    latex插入图片1.单图居中\begin{figure}[htbp]\centering\includegraphics[width=8cm]{images/fig1}\caption{图的说明}\end{figure}2.双图横向并列\begin{figure}[htbp]\begin{minipage}[t]{0.5\linewidth}\centering\includegr…

    2022年6月10日
    32
  • Java 标识符 命名规则 变量 数据类型

    Java 标识符 命名规则 变量 数据类型Java 语法关键字和保留字关键字 被 java 语言赋予了特殊含义 用作专门的用途的字符串所有关键字都是小写 保留字 现有的 java 版本尚未使用 但是以后版本可能作为关键字使用 gotoconst 标识符标识符 java 对各类变量 方法和类等要素命名时使用的字符序列成为标识符 凡是自己可以命名的地方都叫做标识符 由 16 个英文字母大小写 0 9 或者 和 组成 数字不可以用来开头 不可以使用关键字和保留字 但可以包含关键字和保留字 Java 中严格区分大小写 长度度无限制标识符不

    2025年6月8日
    0
  • NAT的双机热备方案

    一般的NAT组网中,内网用户通过单台设备进行NAT转换访问外网,NAT设备承担了所有内外网之间的流量,无法规避单点故障。一旦发生单点故障,将导致内网用户无法与外网通信。随着用户对网络可靠性的要求越来越高,发生单点故障导致网络间断是不可接受的。因此在重要节点处一般都部署两台或者多台设备,构成冗余备份组网,但如果设备之间不能实时的进行数据备份的话,链路切换时还是会导致用户的业务中断。双机热备方案可…

    2022年4月7日
    87
  • mybatis 分页原理_分页机结构原理

    mybatis 分页原理_分页机结构原理Mybatis可以通过传递RowBounds对象,来进行数据库数据的分页操作,然而遗憾的是,该分页操作是对ResultSet结果集进行分页,也就是人们常说的逻辑分页,而非物理分页。RowBo…

    2022年9月22日
    0
  • origin作图图例老是消失_origin画的图不见了

    origin作图图例老是消失_origin画的图不见了记录origin画图遇到的问题及其软件bug解决画图问题如何快速绘制框架画图问题如何快速绘制框架本例子以origin2021版本问题的提出:导入数据之后没有上框和右框(如图)目的:入Excel数据之后直接有上框和右框(也就是能不能设置这么一个模板),如图:解决方法方法一点击图片,找到我红色框的地方,点击即可(据说这种方法在2020版本及其以上即可支持)效果图:方法二:点击查看–显示–框架效果图:PS:美中不足的是,该方法不可以撤销…

    2022年9月21日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号