LuoguP6904 [ICPC2015 WF]Amalgamated Artichokes 题解
Content
已知常数 \(p,a,b,c,d\),我们知道,第 \(k\) 天的股价公式为 \(price_k=p\times(\sin(a\times k+b)+\cos(c\times k+d)+2)\)。根据这个公式,请求出 \(n\) 天以来股票的最大跌幅。
数据范围:\(1\leqslant p\leqslant 1000,0\leqslant a,b,c,d\leqslant 1000,1\leqslant n\leqslant 10^6\)。
Solution
我们一边扫过去,边扫边记录当前的最大股价 \(maxi\),然后拿 \(maxi\) 减去当前的股价,最后取最大值即可。
Code
int p, a, b, c, d, n, curmax;
double price[1000007], ans;
int main() {
scanf("%d%d%d%d%d%d", &p, &a, &b, &c, &d, &n);
for(int i = 1; i <= n; ++i) {
price[i] = p * (sin(a * i + b) + cos(c * i + d) + 2);
if(i == 1) curmax = i;
else if(price[curmax] < price[i]) curmax = i;
else ans = max(ans, price[curmax] - price[i]);
}
printf("%.10lf", ans);
return 0;
}