任务概述
题目描述
One day, CYLL found an interesting piece of commercial from newspaper: the Cyber-restaurant was offering a kind of “Lunch Special” which was said that one could “buy one get two for free”. That is, if you buy one of the dishes on their menu, denoted by d i d_i di with price p i p_i pi, you may get the two neighboring dishes d i − 1 d_{i−1} di−1 and d i + 1 d_{i+1} di+1 for free! If you pick up d 1 d_1 d1, then you may get d 2 d_2 d2 and the last one d n d_n dn for free, and if you choose the last one d n d_n dn, you may get d n − 1 d_{n−1} dn−1 and d 1 d_1 d1 for free.
However, after investigation CYLL realized that there was no free lunch at all. The price p i p_i pi of the i i i-th dish was actually calculated by adding up TWICE the cost c i c_i ci of the dish and HALF of the costs of the two “free” dishes. Now given all the prices on the menu, you are asked to help CYLL find the cost of each of the dishes.
Sample program of judge:
#include <stdio.h>
#define Max_size 10000 /* max number of dishes */
void Price( int n, double p[] );
int main()
{
int n, i;
double p[Max_size];
scanf("%d", &n);
for (i=0; i<n; i++)
scanf("%lf", &p[i]);
Price(n, p);
for (i=0; i<n; i++)
printf("%.2f ", p[i]);
printf("\n");
return 0;
}
/* Your function will be put here */
Sample Input:
12 23.64 17.39 12.77 16.62 10.67 14.85 12.68 26.90 28.30 15.59 37.99 23.18
Sample Output:
9.20 5.58 3.24 7.00 1.99 6.36 2.25 10.01 11.52 0.50 17.65 4.88
算法思路
很简单的一道题,就是解一个线性方程组,而且还是严格对角占优的,所以方法很多。
哦,先把方程组写出来:
{ 2.0 c 1