题目链接:http://poj.org/problem?id=1005
题目分析:
题目看上去很头疼,但是其实核心的内容很简单。就是一道计算半圆面积的问题。
输入建造房子的坐标,计算以(0,0)为圆心,该坐标点与圆心距离为半径的半圆的面积,再除以河水每年侵蚀的面积,不足一年取为一年,求得年数。
源代码:
#include <iostream>
using namespace std;
const double pi = 3.1415926;
int main()
{
int num; //次数
cin>>num;
for (int i = 1; i <= num; i++)
{
double x, y; //坐标
cin>>x>>y;
int year; //年数
year = pi * (x * x + y * y) / 2 / 50 + 1; //半圆面积/每年侵蚀面积
cout<<"Property "<<i<<": This property will begin eroding in year "<<year<<'.'<<endl;
}
cout<<"END OF OUTPUT."<<endl;
system("pause");
return 0;
}