您的位置:首页 > 其它

I Think I Need a Houseboat 1005 PKU

2010-06-06 14:55 381 查看
description:

某个地方被Mississippi河腐蚀每年都会有50square miles,而且总共腐蚀是个半圆,求给定一个点什么时候会被腐蚀

solution:

求该点到(0,0)的长度r,求以r为半径半圆的面积area,除以50即可得到答案

1. 一个难点是浮点型精度的处理,但是好像多想了,题目给出HINT:No property will appear exactly on the semicircle boundary: it will either be inside or outside.

#include <stdio.h>

#define PI 3.1415926535
#define EPS 1e-6

int main()
{
int cases=0,i=0;
double year=0;
double area=0,x=0,y=0;

scanf ("%d",&cases);

for (i=1; i<=cases; i++)
{
scanf ("%lf %lf",&x,&y);
area = (x*x+y*y)*PI/2;

year = area / 50;
printf ("Property %d: This property will begin eroding in year %d.\n",
i,(int)(year-EPS)+1);
}

printf("END OF OUTPUT.\n");

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: