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

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(转载请说明出处)

每天一道算法_6_I Think I Need a Houseboat的更多相关文章

  1. 一道算法题目, 二行代码, Binary Tree

    June 8, 2015 我最喜欢的一道算法题目, 二行代码. 编程序需要很强的逻辑思维, 多问几个为什么, 可不可以简化.想一想, 二行代码, 五分钟就可以搞定; 2015年网上大家热议的 Home ...

  2. 每天一道算法题(4)——O(1)时间内删除链表节点

    1.思路 假设链表......---A--B--C--D....,要删除B.一般的做法是遍历链表并记录前驱节点,修改指针,时间为O(n).删除节点的实质为更改后驱指针指向.这里,复制C的内容至B(此时 ...

  3. 每天一道算法题-leetcode136-只出现一次的数字

    前言 打卡第一天 2019.10.26日打卡 算法,即解决问题的方法.同一个问题,使用不同的算法,虽然得到的结果相同,但是耗费的时间和资源是不同的.这就需要我们学习算法,找出哪个算法更好. 大家都知道 ...

  4. 从一道算法题实现一个文本diff小工具

    众所周知,很多社区都是有内容审核机制的,除了第一次发布,后续的修改也需要审核,最粗暴的方式当然是从头再看一遍,但是编辑肯定想弄死你,显然这样效率比较低,比如就改了一个错别字,再看几遍可能也看不出来,所 ...

  5. 【每天一道算法题】时间复杂度为O(n)的排序

    有1,2,……一直到n的无序数组,求排序算法,并且要求时间复杂度为O(n),空间复杂度为O(1),使用交换,而且一次只能交换两个数. 这个是以前看到的算法题,题目不难.但是要求比较多,排序算法中,时间 ...

  6. 每天一道算法题(14)——N个降序数组,找到最大的K个数

     题目: 假定有20个有序数组,每个数组有500个数字,降序排列,数字类型32位uint数值,现在需要取出这10000个数字中最大的500个. 思路 (1).建立大顶堆,维度为数组的个数,这里为20( ...

  7. c++ LeetCode(初级数组篇)十一道算法例题代码详解(一)

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/10940636.html 唉!最近忙着面试找实习,然后都是面试的很多是leetcode的算法题, ...

  8. 一道算法题加深我对C++中map函数的理解

    一.一道题目引发我对map函数的考量 首先是题目大意:有n个银行,a[i]表示这个人在第i个银行有a[i]块钱(可以是负数),所有银行的钱加起来正好是0.每次只能在相邻的银行之间转账,问最少要转多少次 ...

  9. 提前批笔试一道算法题的Java实现

    题目描述 这是2021广联达校招提前批笔试算法题之一. 我们希望一个序列中的元素是各不相同的,但是理想和显示往往是有差距的.现在给出一个序列A,其中难免有相同的元素,现在提供了一种变化方式,使得经过若 ...

随机推荐

  1. window scipy install

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy whl包,使用pip install xx.whl  安装 1:先安装 numpy+mkl.  whl ...

  2. linux下安装busybox

    1.获取busybox源码并解压,这里使用天嵌提供的“busybox-1.16.0.tar.bz2” #tar xvf busybox-.tar.bz2 -C / 解压的目的地址实际上是:/opt/E ...

  3. 关于Memcache使用的工具类

    分布式缓存有它自己的好处 . 下面的 ConstValue.sessionId  是一个常量 public static readonly string sessionId = "sessi ...

  4. C# 下载资源

    //创建一个初始化请求对象 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://wwww.b ...

  5. FutureTask源码解读

    import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.ut ...

  6. mvc Model元数据【学习笔记】

    页面中Html.Editorfor(model=>model.fieldname)这些方法,都是通过Model的元数据来生成html的,我们如果想控制最终生成的html,可以通过修改元数据来实现 ...

  7. Entity Framework 实践系列 —— 搞好关系 - 单相思(单向一对一,one-to-one)【转】

    原以为躲入代码世界,就可以不用搞关系,哪知“关系无处不在”.写代码多年之后,终于明白“面向对象的关键是搞好对象之间的关系”.而Entity Framework作为ORM中的明日之星,首当其冲的使命就是 ...

  8. ZeroBraneStudio之支持GBK文件编码

    费了好大劲终于搞定了让ZBS支持打开GBK文件了.记录下过程: 看源码发现ZBS打开文件时会调用src\editor\commands.lua中的LoadFile函数,代码如下: local file ...

  9. ie8如何支持html5

    两种方法 : 一:Coding JavaScript <!--[if lt IE9]> <script>    (function() {     if (!      /*@ ...

  10. iOS:关于获取网络类型和运营商信息

    目录 1. 获取运营商网络类型 2. 获取运营商信息 返回目录 1. 获取运营商网络类型 Apple的Reachability Sample看起来不错,但是只可以判断是否连接到互联网和是否连接Wifi ...