题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1049
本题主要是要理解题意,以房子坐标与原点为半径,原点为圆心做一个圆,算出面积,之后将它除以五十,因为侵蚀速度是每年50平方英里,所以算出最大年限,同时要注意年限的取法,可以通过ceil()函数或者通过直接加一就可以实现。还要进行宏定义圆周率,有的题当中对圆周率要求不同。
代码:
#include<stdio.h>
#include<math.h>
#define PI 3.1415926
int main()
{
int N,i=1;
scanf("%d",&N);
while(N--)
{
int year;
float x,y,s,r;
scanf("%f%f",&x,&y);
r=sqrt(x*x+y*y);
s=PI*r*r/2.0;
year=(int)s/50.0;
printf("Property %d: ",i++);
printf("This property will begin eroding in year %d.\n",year+1);
}
printf("END OF OUTPUT.\n");
return 0;
}