ACM/ICPC WORLD FINAL 2015 A题

 Fatima Cynara is an analyst at Amalgamated Artichokes (AA). As with any company, AA has had some very good times as well as some bad ones. Fatima does trending analysis of the stock prices for AA, and she wants to determine the largest decline in stock prices over various time spans. For example, if over a span of time the stock prices were 19  19, 12  12, 13  13, 11  11, 20  20 and 14  14, then the largest decline would be 8  8 between the first and fourth price. If the last price had been 10  10 instead of 14  14, then the largest decline would have been 10  10 between the last two prices.

Fatima has done some previous analyses and has found that the stock price over any period of time can be modelled reasonably accurately with the following equation:

price(k)=p(sin(ak+b)+cos(ck+d)+2)  price⁡(k)=p⋅(sin⁡(a⋅k+b)+cos⁡(c⋅k+d)+2)

where p  p, a  a, b  b, c  c and d  d are constants. Fatima would like you to write a program to determine the largest price decline over a given sequence of prices. Figure 1 illustrates the price function for Sample Input 1. You have to consider the prices only for integer values of k  k.

\includegraphics[width=0.9\textwidth ]{sample1}
Figure 1: Sample Input 1. The largest decline occurs from the fourth to the seventh price.

Input

The input consists of a single line containing 6  6 integers p  p ( 1p1000  1≤p≤1000), a  a, b  b, c  c, d  d ( 0a,b,c,d1000  0≤a,b,c,d≤1000) and n  n ( 1n10 6   1≤n≤106). The first 5  5 integers are described above. The sequence of stock prices to consider is price(1),price(2),,price(n)  price(1),price(2),…,price⁡(n).

Output

Display the maximum decline in the stock prices. If there is no decline, display the number 0  0. Your output should have an absolute or relative error of at most 10 6   10−6.

Sample Input 1Sample Output 1
42 1 23 4 8 10
104.855110477
Sample Input 2Sample Output 2
100 7 615 998 801 3
0.00

Sample Input 3Sample Output 3
100 432 406 867 60 1000
399.303813

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 1000100
using namespace std;
double price[MAXN];
double ans, maxn; 
int p, a, b, c, d, n;

int main()
{
	while (~scanf("%d%d%d%d%d%d", &p, &a, &b, &c, &d, &n))
	{
		ans = 0;
		for (int i = 1; i <= n; i++) 
			price[i] = p*(sin(a*i + b) + cos(c*i + d) + 2);
		maxn = price[1];
		for (int i = 2; i <= n; i++)
		{
			if (price[i]>maxn)  
				maxn = price[i];
			else    
				ans = max(ans, maxn - price[i]);
		}
		printf("%.10lf\n", ans);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值