題意 : 給一個合成函式 ,尋找其中最大的下降高度
注意 : 若跑兩個for迴圈會TLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cmath> | |
#include<iomanip> | |
#include <limits> | |
using namespace std; | |
typedef numeric_limits< double > dbl; | |
double test[1000001]; | |
double p,a,b,c,d,n; | |
double price(double k){ | |
return p * (sin(a * k + b) + cos(c * k + d) + 2); | |
} | |
int main(){ | |
while(cin>>p>>a>>b>>c>>d>>n){ | |
for(int y=1;y<=n;y++) { | |
test[y] = price(y); | |
} | |
double ans = 0; | |
double maxi = test[1]; | |
for(int i=2;i<=n;i++){ | |
if(test[i]>maxi) maxi = test[i]; | |
else ans = max(maxi-test[i],ans); | |
} | |
//max1 = maxi-minj; | |
cout.precision(dbl::digits10); | |
if(ans==0) cout<<"0.00"<<endl; | |
else cout<<ans<<endl; | |
} | |
} |
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。