杭电ACM 三 选地盖房防水淹(Math.ceil)

问题及代码:

Problem 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.”

Notes:

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.

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.
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:team.cpp
*作    者:冷基栋
*完成日期:2015年2月15日
*版 本 号:v1.0
*/
#include<iostream>
#include<cmath>
using namespace std;
const double pi=3.1415927;
int main()

{
    int i=1,n;
    int year;
    double x,y,r,area;
    cin>>n;
    while(n--)
    {
        cin>>x>>y;
        r=x*x+y*y;
        area=pi*r/2.0;
        year=ceil(area/50.0);
        cout<<"Property "<<i++<<":";
        cout<<" This property will begin eroding in year "<<year<<". "<<endl;

    }
    cout<<"END OF OUTPUT. ";
    return 0;
}

运行结果:

知识点总结:

Source: Mid-Atlantic USA 2001

题目大意:弗雷德先生正在考虑在路易斯安娜州买一块地造房子,在土地调查中,他了解到由于密西西比河的侵蚀,路易斯安那州正以每年50平方英里的速度变小。弗雷德先生想知道他买的那块地是否会被侵蚀掉,经过进一步的研究,弗雷德先生发现将要被侵蚀的土地为半圆形,半圆是一个以(0,0)为中心的圆的一半,半圆的直边是x轴。x轴以下的部分在水中,第一年开始时,圆的面积是0,半圆如图所示。第一行输入一个整数n,表示有几组测试数据,接下来有n行,每行是(x,y)的坐标,弗雷德正在考虑地皮的位置,坐标值是以英里为单位的浮点数,坐标y不会为负数,这两个数不会都为0,输出经过多少年后,弗雷德的房子会被淹没。

算法分析:有(x,y)坐标可求出半径r,然后就可以求出面积,利用循环语句来求出年数,(也可以用面积除以50)。

Math.ceil()

Math.ceil()是常见编程语言中的常用代码,ceil() 方法执行的是向上取整计算,它返回的是大于或等于函数参数,并且与之最接近的整数。[

Math.ceil(x)

参数:X(必需)

例如:

Math.ceil(12.2)//返回13

Math.ceil(12.7)//返回13

Math.ceil(12.0)// 返回12

学习心得:

自己不要把题目想复杂

好好学习 天天向上



时间: 2024-10-10 16:44:47

杭电ACM 三 选地盖房防水淹(Math.ceil)的相关文章

杭电ACM 三 大数取模

题目及代码 Problem Description As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B. To make the problem easier, I promise that B will be smaller than 100000. I

杭电ACM 三 圆桌会议倒序换座

Problem Description HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家的讨论后一般没有解决不了的问题,这也只有HDU ACM集训队特有的圆桌会议,有一天你也可以进来体会一下哦:),在一天在讨论的时候,Eddy想出了一个极为古怪的想法,如果他们在每一分钟内,一对相邻的两个ACM队员交换一下位子,那么要多少时间才能得到与原始状态相反的座位顺序呢?(即对于每个队员,原先在他左面的队员

杭电ACM 三 重力搭牌

问题及代码: Problem Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you c

杭电ACM 三 动能定理 物理

问题及代码 Problem Description Once again, James Bond is fleeing from some evil people who want to see him dead. Fortunately, he has left a bungee rope on a nearby highway bridge which he can use to escape from his enemies. His plan is to attach one end o

杭电ACM 三 在坐标系中的微积分

问题及代码 Problem Description Ignatius bought a land last week, but he didn't know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the p

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

杭电ACM水仙花数

水仙花数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 96473    Accepted Submission(s): 28632 Problem Description 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: "水仙花数"是指一个三位数,它的各位数字的立方和等于其本身,比如:1

杭电ACM 2036 改革春风吹满地

已知直角坐标系3点p(a,b),m(c,d),n(e,f) 求三角形pmn面积的表达式! 解: 无论三角形的顶点位置如何,△PMN总可以用一个直角梯形(或矩形)和两个直角三角形面积的和差来表示而在直角坐标系中,已知直角梯形和直角三角形的顶点的坐标,其面积是比较好求的.下面以一种情形来说明这个方法,其它情形方法一样,表达式也一样(表达式最好加上绝对值,确保是正值)如图情形(P在上方,M在左下,N在右下),过P作X轴的平行线L,作MA⊥L,NB⊥L(设P在A.B之间)则A.B的坐标是A(c,b),B

杭电ACM Java实现样例

若使用Java求解杭电ACM,答案提交必须注意两点: 1.类名一定得是Main,否则服务器无法编译: 2.必须用while进行输入判断. 以1000题测试题为例,代码如下: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); while(scan.hasNextInt()) { int a=scan.n