Math Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3019 Accepted Submission(s): 720
Problem Description
Here has an function:
f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)
Please figure out the maximum result of f(x).
f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)
Please figure out the maximum result of f(x).
Input
Multiple test cases(less than 100). For each test case, there will be only 1 line contains 6 numbers a, b, c, d, L and R.
(−10≤a,b,c,d≤10,−100≤L≤R≤100)
Output
For each test case, print the answer that was rounded to 2 digits after decimal point in 1 line.
Sample Input
1.00 2.00 3.00 4.00 5.00 6.00
Sample Output
310.00题意:求给定区间给定系数的f(x)最大值思路:最稳妥的方法就是手算,用导数求极值,然后处理好正负,再和区间端点值对比,这样得注意a==0的情况(二次方程的求根)粘点别人的代码http://www.cnblogs.com/flipped/p/5245237.htmlhttp://www.cnblogs.com/Howe-Young/p/4808161.htmlhttp://blog.csdn.net/u012860063/article/details/43114419哈哈,其实算算误差这题没必要这么麻烦,给定区间的极限是[-100,100],以步长0.0001(0.00005应该也行)暴力枚举(l和r)之间的值,求出最大值再和两端点比较就可以AC,最终保留两位小数10^-4的误差足以被屏蔽掉(-3次方不行,会卡数据,而且-4次方刚好满足时间复杂度要求)#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <string> #include <stack> using namespace std; typedef long long ll; #define PI 3.1415926535897932 #define E 2.718281828459045 #define INF 0x3f3f3f3f #define mod 1000000007 const int M=1005; int n,m; int cnt; int sx,sy,sz; int mp[1000][1000]; int pa[M*10],rankk[M]; int head[M*6],vis[M*100]; int dis[M*100]; ll prime[M*1000]; bool isprime[M*1000]; int lowcost[M],closet[M]; char st1[5050],st2[5050]; int len[M*6]; typedef pair<int ,int> ac; //vector<int> g[M*10]; int has[10500]; int month[13]= {0,31,59,90,120,151,181,212,243,273,304,334,0}; int dir[8][2]= {{0,1},{0,-1},{-1,0},{1,0},{1,1},{1,-1},{-1,1},{-1,-1}}; void getpri() { ll i; int j; cnt=0; memset(isprime,false,sizeof(isprime)); for(i=2; i<1000000LL; i++) { if(!isprime[i])prime[cnt++]=i; for(j=0; j<cnt&&prime[j]*i<1000000LL; j++) { isprime[i*prime[j]]=1; if(i%prime[j]==0)break; } } } struct node { int v,w; node(int vv,int ww) { v=vv; w=ww; } }; vector<int> g[M*100]; string str[1000]; ll sum[1050000]; #define eps 1e-4 double ans; int main() { //printf("%.2lf\n",max(1.333,1.332)); double a,b,c,d,l,r; while(~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&l,&r)) { ans=0.0; while(l<=r) { ans= max(ans ,fabs(a*l*l*l+b*l*l+c*l+d));//忘加绝对值都WA哭了,还以为这思路不可行呢。。。 l += eps; } l=r; ans = max(ans ,fabs(a*l*l*l+b*l*l+c*l+d)); printf("%.2lf\n" ,ans); } return 0; }