hdu 1065 I Think I Need a Houseboat

本文详细解析了一段使用C++编写的洪水侵蚀模拟代码。该代码通过输入坐标系中的点(x, y),计算出该点到原点的距离d,并基于距离d和π值计算出侵蚀开始的年份i。每一轮循环中,都会计算出一个新的半径r,如果d小于等于r,则输出该属性将在第i年开始侵蚀。

参考:https://blog.youkuaiyun.com/neoxuhaotian/article/details/6112147

https://blog.youkuaiyun.com/lionel_d/article/details/44198125

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #define pi 3.1415926
 6 using namespace std;
 7 int main()
 8 {
 9     int t;
10     while (cin>>t)
11     {
12         for (int j=1;j<=t;j++)
13         {
14             float d,x,y;
15             cin>>x>>y;
16             d=sqrt(x*x+y*y);
17             for (int i=1;;i++)
18             {
19                 float s=i*100.0;
20                 float r=sqrt(s/pi);
21                 if (d<=r)
22                 {
23                     cout<<"Property "<<j<<": This property will begin eroding in year "<<i<<'.'<<endl;
24                     break;
25                 }
26             }
27         }
28         cout<<"END OF OUTPUT."<<endl;//注意此句位置,不要误放入j循环内!
29     }
30 
31     return 0;
32 }

 

转载于:https://www.cnblogs.com/hemeiwolong/p/9397847.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值