hd515和hd615性能差距,HDU 5105

 2023-12-25 阅读 27 评论 0

摘要:題意略。 思路: hd515和hd615性能差距、考察導數和分類討論的思想,因為在做題時少討論一種情況,所以wa了。 #include<bits/stdc++.h> using namespace std;double a,b,c,d,L,R;double func(double x){return fabs(a * x * x * x + b *

題意略。

思路:

hd515和hd615性能差距、考察導數和分類討論的思想,因為在做題時少討論一種情況,所以wa了。

#include<bits/stdc++.h>
using namespace std;double a,b,c,d,L,R;double func(double x){return fabs(a * x * x * x + b * x * x + c * x + d);
}int main(){while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&L,&R) == 6){double ans = 0;double ansl = func(L),ansr = func(R);if(a != 0){double d = b * b - 3 * a * c;if(d <= 0){ans = max(ansl,ansr);}else{double x1 = (-1 * b - sqrt(d)) / (3 * a);double x2 = (-1 * b + sqrt(d)) / (3 * a);double ans1 = func(x1),ans2 = func(x2);if(L <= x1 && x2 <= R){ans = max(max(ans1,ans2),max(ansl,ansr));}else if(R <= x1 || L >= x2){ans = max(ansl,ansr);}else if(L <= x1 && x1 <= R && R <= x2){ans = max(ans1,max(ansl,ansr));}else if(x1 <= L && R <= x2){ans = max(ansl,ansr);}else if(x1 <= L && L <= x2 && x2 <= R){ans = max(ans2,max(ansl,ansr));}}}else if(b != 0){double x0 = -c / (2 * b);if(R <= x0){ans = max(ansl,ansr);}else if(L <= x0 && x0 <= R){ans = max(func(x0),max(ansl,ansr));}else{ans = max(ansl,ansr);}}else if(c != 0){ans = max(ansl,ansr);}else{ans = fabs(d);}printf("%.2lf\n",ans);}return 0;
}

?

轉載于:https://www.cnblogs.com/tiberius/p/9164288.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/194957.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息