• UVA


    Description

    Download as PDF
    Problem F
    Supermean
    Time Limit: 2 second
    "I have not failed. I've just found 10,000 ways that won't work."
    Thomas Edison

    Do you know how to compute the mean (or average) of n numbers? Well, that's not good enough for me. I want the supermean! "What's a supermean," you ask?

    I'll tell you. List the n given numbers in non-decreasing order. Now compute the average of each pair of adjacent numbers. This will give you n - 1 numbers listed in non-decreasing order. Repeat this process on the new list of numbers until you are left with just one number - the supermean. I tried writing a program to do this, but it's too slow. :-( Can you help me?

    Input
    The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line containing n (0<n<=50000). The next line will contain the n input numbers, each one between -1000 and 1000, in non-decreasing order.

    Output
    For each test case, output one line containing "Case #x:" followed by the supermean, rounded to 3 fractional digits.

    Sample Input Sample Output
    4
    1
    10.4
    2
    1.0 2.2
    3
    1 2 3
    5
    1 2 3 4 5
    
    Case #1: 10.400
    Case #2: 1.600
    Case #3: 2.000
    Case #4: 3.000
    

    Problemsetter: Igor Naverniouk

    题意:给出n个数,每相邻的两个数求平均数。将得到n-1个,然后再两两求平均数,依次类推直到最后一个。求这个数是多少

    思路:系数的话非常easy想到是杨辉三角的系数,可是由于n大太,所以为了防止溢出我们用log来储存。每一项的通式是:i=0n1C[n1][i]num[i]2n1

    然后就是在推组合数的同一时候对数处理

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    const int maxn = 50005;
    
    double C[maxn], num[maxn];
    
    int main() {
    	int t, n, cas = 1;
    	scanf("%d", &t);
    	while (t--) {
    		scanf("%d", &n);
    		for (int i = 0; i < n; i++)
    			scanf("%lf", &num[i]);
    
    		double ans = 0.0, tmp = log10(1);
    		for (int i = 0; i < n; i++) { 
    			if (i) 
    				tmp = tmp + log10(n-i) - log10(i);
    			
    			if (num[i] < 0)
    				ans -= pow(10, tmp + log10(-num[i]) - (n-1)*log10(2));
    			else ans += pow(10, tmp + log10(num[i]) - (n-1)*log10(2));
    		}
    
    		printf("Case #%d: %.3lf
    ", cas++, ans);
    	}
    	return 0;
    }



  • 相关阅读:
    黑马程序员-winform视频总结的一些知识点
    如何让360兼容模式打开网页和极速模式打开一样
    [2016-10-24]jQuery学习回顾笔记1.0
    鼠标上下滑动总是放大缩小页面,按住ctrl+0
    按钮在苹果手机显示不正常
    鼠标悬停图片放大
    关于高度
    如何做出透明背景的flash动画
    复选框css
    HTML CSS 特殊字符表(转载)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/5043041.html
Copyright © 2020-2023  润新知