码迷,mamicode.com
首页 > 其他好文 > 详细

uva 10014 - Simple calculations

时间:2014-12-30 11:44:19      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

数列递推,求出公式计算按要求输出即可。

代码 :

import java.util.*;

public class Main10014 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		while(t-- > 0) {
			int n = scan.nextInt();
			double a0 = scan.nextDouble();
			double an = scan.nextDouble();
			double c, sum = 0;
			for(int i=0; i<n; i++) {
				c = scan.nextDouble();
				sum += (n-i)*c;
			}
			
			System.out.printf("%.2f\n",((n * a0 + an - 2 * sum) / (n + 1)));
			if(t != 0)
				System.out.println();
			
		}

	}

}


 

uva 10014 - Simple calculations

标签:

原文地址:http://blog.csdn.net/wxisme/article/details/42263943

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!