3

POJ-1005 I Think I Need a Houseboat 解题思路

 2 years ago
source link: https://blog.sbw.so/u/poj-1005-i-think-i-need-a-houseboat-ac-code.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

POJ-1005 I Think I Need a Houseboat 解题思路

来源: 石博文博客 | 浏览: 1867 | 评论: 0 发表时间: 2019-03-21

POJ 1005,船屋。这是一道比较简单的几何相关的计算题,只需要推导出公式即可轻松解决。不过这个题的英文描述理解起来挺抽象,大概意思是:从坐标(0, 0)开始,有一个圆形的区域,第1年的时候,这个圆形的面积为0。这个圆形每年扩大,每年扩大的面积是50,问给定一个坐标(x, y),这个圆形多久能覆盖到这个坐标。

POJ-1005 I Think I Need a Houseboat

我们假设在给定的坐标(x, y)被恰好覆盖时,即一个圆通过点(x, y)。此时可知这个圆形的半径为

POJ-1005 I Think I Need a Houseboat

那么这个圆的面积为

POJ-1005 I Think I Need a Houseboat

由于题目中是个半圆,每年增长的面积为50,所以需要的年数为

POJ-1005 I Think I Need a Houseboat

由此即可轻松写出解题代码:

#include <cstdio>
#define M_PI 3.1415926
int main()
{
int total;
double x, y;
scanf("%d", &total);
for (int i(0); i != total;)
{
scanf("%lf %lf", &x, &y);
int years = (M_PI * (x * x + y * y) * 0.5) / 50.0 + 1;
printf("Property %d: This property will begin eroding in year %d.\n", ++i, years);
}
printf("END OF OUTPUT.");
return 0;
}

引用本文请以超链接形式保留本文地址

没有人评论过此文,还不快抢个沙发!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK