这道题一开始题目没看懂,总以为是从两边开始腐蚀的,后来发现原来是从中间开始向两边扩散腐蚀的,读懂题目后就可以秒做了,我是写了一个函数就是返回第i年时的腐蚀半径是多少,和给定的目标点对比一下distance就好了。
#include<iostream>
#include<stdio.h>
#include<math.h>
#define exp 1e-6
#define PI (acos(-1))
using namespace std;
double r;
double Distance;
double cal(int sum){
return (sqrt(sum*2/PI));
}
int main(){
r=sqrt(100/PI);
int n;
// freopen("input.txt","r",stdin);
cin>>n;
double x,y;
double sum,ans;
for(int i=1;i<=n;i++){
sum=0;
ans=0;
cin>>x>>y;
Distance=sqrt(x*x+y*y);
for(int year=1;;year++){
sum+=50;
ans=cal(sum);
if(ans>=Distance+exp){
printf("Property %d: This property will begin eroding in year %d.\n",i,year);
break;
}
}
}
printf("END OF OUTPUT.\n");
}