首页 > 代码库 > POJ-1005 I Think I Need a Houseboat

POJ-1005 I Think I Need a Houseboat

【问题描述】

Fred想在一块地上买房子,但那块地每年都会收缩50m2,给定一个房子坐标,输出几年后房子会被侵蚀入海中。

【思路分析】

该题也算是简单题,只要读懂题目就没什么问题了。

唯一要注意的地方是每年会收缩50m2,如果在上一年的基础上算收缩50m2会呈一个半环形,比较麻烦。索性直接计算出从开始到某一年收缩的总量,这时只要求半圆的半径就可解决。

 

【附:完整代码】

/** POJ-1005  I Think I Need a Houseboat*/#include <iostream>#include <cmath>using namespace std;#define PI 3.1415926int main(){    int n, i = 1;    cin>>n;    while (i <= n)    {        double x, y;        cin>>x>>y;        double distance = sqrt(x*x + y*y);        int years;        for (years = 1; true; years++)        {            double shrinkingArea = years * 50.0;            double shrinkingRadius = sqrt(2 * shrinkingArea / PI);            if (shrinkingRadius >= distance)                break;        }                cout<<"Property "<<i++<<": This property will begin eroding in year "<<years<<"."<<endl;    }    cout<<"END OF OUTPUT."<<endl;    return 0;}

POJ-1005 I Think I Need a Houseboat