每天一道算法_6_I Think I Need a Houseboat
今天的题目是I Think I Need a Houseboat
如下:
Description
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
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
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的更多相关文章
- 一道算法题目, 二行代码, Binary Tree
June 8, 2015 我最喜欢的一道算法题目, 二行代码. 编程序需要很强的逻辑思维, 多问几个为什么, 可不可以简化.想一想, 二行代码, 五分钟就可以搞定; 2015年网上大家热议的 Home ...
- 每天一道算法题(4)——O(1)时间内删除链表节点
1.思路 假设链表......---A--B--C--D....,要删除B.一般的做法是遍历链表并记录前驱节点,修改指针,时间为O(n).删除节点的实质为更改后驱指针指向.这里,复制C的内容至B(此时 ...
- 每天一道算法题-leetcode136-只出现一次的数字
前言 打卡第一天 2019.10.26日打卡 算法,即解决问题的方法.同一个问题,使用不同的算法,虽然得到的结果相同,但是耗费的时间和资源是不同的.这就需要我们学习算法,找出哪个算法更好. 大家都知道 ...
- 从一道算法题实现一个文本diff小工具
众所周知,很多社区都是有内容审核机制的,除了第一次发布,后续的修改也需要审核,最粗暴的方式当然是从头再看一遍,但是编辑肯定想弄死你,显然这样效率比较低,比如就改了一个错别字,再看几遍可能也看不出来,所 ...
- 【每天一道算法题】时间复杂度为O(n)的排序
有1,2,……一直到n的无序数组,求排序算法,并且要求时间复杂度为O(n),空间复杂度为O(1),使用交换,而且一次只能交换两个数. 这个是以前看到的算法题,题目不难.但是要求比较多,排序算法中,时间 ...
- 每天一道算法题(14)——N个降序数组,找到最大的K个数
题目: 假定有20个有序数组,每个数组有500个数字,降序排列,数字类型32位uint数值,现在需要取出这10000个数字中最大的500个. 思路 (1).建立大顶堆,维度为数组的个数,这里为20( ...
- c++ LeetCode(初级数组篇)十一道算法例题代码详解(一)
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/10940636.html 唉!最近忙着面试找实习,然后都是面试的很多是leetcode的算法题, ...
- 一道算法题加深我对C++中map函数的理解
一.一道题目引发我对map函数的考量 首先是题目大意:有n个银行,a[i]表示这个人在第i个银行有a[i]块钱(可以是负数),所有银行的钱加起来正好是0.每次只能在相邻的银行之间转账,问最少要转多少次 ...
- 提前批笔试一道算法题的Java实现
题目描述 这是2021广联达校招提前批笔试算法题之一. 我们希望一个序列中的元素是各不相同的,但是理想和显示往往是有差距的.现在给出一个序列A,其中难免有相同的元素,现在提供了一种变化方式,使得经过若 ...
随机推荐
- OC相关-02:oc和c的基本差异
前言: 面向过程和面向对象. 简单的说,面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用. 面向对象是把构成问题事务分解成各个对象,建立对象的目的不 ...
- C# 推送信息到APNs
iPhone消息推送机制实现与探讨 class Program { public static DateTime? Expiration { get; set; } ...
- CSS图片去色
.imgFilter { filter: grayscale(100%); -webkit-filter: grayscale(100%); -moz-filter: grayscale(100%); ...
- windows 基础及基本软件测试环境搭建
- odoo8 email
?? return 地址和 from 地址不一致,为什么不能发送成功? replay地址. 根据对象(比如purchase.order)发送邮件,可以通过supermessage_get_email_ ...
- WPF 自定义路由事件
如何:创建自定义路由事件 首先自定义事件支持事件路由,需要使用 RegisterRoutedEvent 方法注册 RoutedEvent C#语法 public static RoutedEvent ...
- OC语言-01类和对象
// cc 文件名.m -framework Foundation 编译链接 #import <Foundation/Foundation.h> //枚举性别 typedef enum{ ...
- Laravel框架——分页
第一种:查询时实现分页(不能使用groupBy) $users = App\User::paginate(15); or $users = User::where('votes', '>', 1 ...
- EFBaseDal
public class BaseDal<T> where T : class, new() { DataModelContainer db = new DataMod ...
- jsp表单提交中文乱码的解决
<%@ page language="Java" contentType="text/html; charset=utf-8 " pageEncod ...