ZOJ 1049 I Think I Need a Houseboat

时间:2023-12-23 16:07:14

原题链接

题目大意:Fred想在Louisiana买一套房子,但是堤坝不牢固,每年都要被河水侵蚀50平方英里。题目给出他豪宅的坐标,要求他*移民搬迁的年份。

解法:也没什么好说的,先求出两点间的距离,即半径,然后算出面积,在除以每年塌方的面积,向上取整即可。

参考代码:

#include <stdio.h>
#include <math.h>
#define PI 3.14
int main(){
int n=1,N,year;
float X,Y,dist,area;
scanf("%d",&N);
while(n<=N){
scanf("%f%f",&X,&Y);
dist = X*X+Y*Y;
dist = sqrt(dist);
area = PI*dist*dist/2/50;
year = ceil(area);
printf("Property %d: This property will begin eroding in year %d.\n",n,year);
n++;
}
printf("END OF OUTPUT.");
return 0;
}