2 solutions
-
3
这道题花了我一个多小时,最后发现PI写错了
①PI=acos(-1)而我写成了PI=cos(-1),一度怀疑人生
②r1的求解比较难想到,是利用的三角函数 看图吧!
//非(常规)二分,含有精度,估算高度而不是去计算高度 //使用到eps的l,r不需要+1-1 #include<iostream> #include<math.h> using namespace std; #define PI acos(-1) double r, R, H, V, v2, r1; bool check(double h) { r1 = (h / H) * (R - r) + r; v2 = (1.0 / 3.0) * PI * h * (r1 * r1 + r * r1 + r * r); return v2 <= V; } int main() { int t; scanf("%d", &t); while (t--) { scanf("%lf%lf%lf%lf", &r, &R, &H, &V); double l = 0, r = 100, mid; while (r - l > 1e-7) { mid = (l + r) / 2; if (check(mid)) l=mid; else r=mid; } printf("%.6lf", r); } return 0; }
-
0
二分,条件找好,取号精度就可以了
#include<iostream> using namespace std; #define pai 3.141592653589 int t; double rd,ru,h,v; bool check(double H,double r){ double V=(1.0/3.0)*pai*H*(rd*rd+r*r+r*rd); if(V<=v)return false; else return true; } double find(double l,double r){ double mid,R; while(l<=r){ mid=(r+l)/2.0; R=mid*(ru-rd)/h+rd; if(check(mid,R))r=mid-0.0000001; else l=mid+0.0000001; } return l; } int main(){ cin>>t; while(t--){ cin>>rd>>ru>>h>>v; double ans=find(0,h); printf("%.6lf",ans); } return 0; }
- 1
Information
- ID
- 282
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 116
- Accepted
- 35
- Uploaded By