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.

ACM/ICPC WORLD FINAL 2015 A题_第1张图片
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 1 Sample Output 1
42 1 23 4 8 10
104.855110477
Sample Input 2 Sample Output 2
100 7 615 998 801 3
0.00

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

#include
#include
#include
#include
#include
#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);
	}
}

你可能感兴趣的:(ACM/ICPC WORLD FINAL 2015 A题)