题目链接:
http://poj.org/problem?id=1005
大致题意:
密西西比河岸某处陆地因为河水侵蚀,每年陆地面积都在减少,每年减少50平方英里,减少的陆地面积呈半圆形,即该半圆形面积以每年50平方英里的速度增长。在第一年初时,该半圆形面积为0,半圆形的圆心坐标为(0,0),现在的任务是给定一个坐标,求出该坐标在哪一年年底会被河水侵蚀。假设给定的坐标到圆心的距离不会等于半圆的半径。
思路:
简单数学题,设前一年的半径为r2, 今年的半径为r1 ,则3.14 * r1 ^ 2 / 2 - 3.14 * r2 ^ 2 / 2 = 50,求出r2后即可
#include <iostream> #include <math.h> using namespace std; const double pai = 100 / 3.1415926; int main() { int n, test = 1; double r1, r2; scanf("%d", &n); while (n--) { r2 = 0.0; double x, y; scanf("%lf %lf", &x, &y); double dis = x * x + y * y; int t = 0; while (1) { ++t; r1 = sqrt(pai + r2 * r2); r2 = r1; if (r1 * r1> dis) break; } printf("Property %d: This property will begin eroding in year %d.\n", test++, t); } printf("END OF OUTPUT.\n"); return 0; }