Description


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=0n−1C[n−1][i]∗num[i]2n−1

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

#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\n", cas++, ans);
}
return 0;
}



UVA - 10883 Supermean的更多相关文章

  1. UVa 10883 (组合数 对数) Supermean

    在纸上演算一下就能看出答案是:sum{ C(n-1, i) * a[i] / 2^(n-1) | 0 ≤ i ≤ n-1 } 组合数可以通过递推计算:C(n, k) = C(n, k-1) * (n- ...

  2. uva - 10833 Supermean(二项式系数,对指数)

    模拟发现,每个元素求和时,元素的系数是二项式系数,于是ans=sum(C(n-1,i)*a[i]/2^(n-1)),但是n太大,直接求会溢出,其实double的范围还是挺大的,所以可以将组合数转化成对 ...

  3. UVa 10883 超级平均数(二项式系数+对数计算)

    https://vjudge.net/problem/UVA-10883 题意: 给出n个数,每相邻两个数求平均数,依次类推,最后得到1个数,求该数. 思路: 演算一下可以发现最后各个数的系数就是二项 ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. 解决IIS6.0不能下载EXE文件之妙方!

    2003系统 IIS6建站 有EXE文件下载 但老是不让下载.当我把站删除再建后可以下载,但过一会又不让下载了.另,MIME里有EXE这项!请问这是为什么?应如何处理? 答案: win2003服务器允 ...

  2. 文件上传利器JQuery上传插件Uploadify

    在做日常项目中,经常在后台需要上传图片等资源文件,之前使用过几次这个组件,感觉非常好用 ,但是每次使用的时候都是需要经过一番查阅,所以还不如记住在这里,以后使用的时候就翻翻. 他的官方网站如下:htt ...

  3. 负载均衡、LVS概述

    1. 负载均衡概述 负载均衡的基本思路是:在一个服务器集群中尽可能的平衡负载量.通常的做法是在服务器前端设置一个负载均衡器(一般是专门的硬件设备).然后负载均衡器将请求的连接路由到最空闲的可用服务器. ...

  4. [selenium webdriver Java]常用api

    1. 获取元素文本 WebElement类的getText()方法返回元素的innerText属性.所以元素里如果有子节点一样也会被返回出来.如下所示 public class GetText { @ ...

  5. <转>SpringMVC与Struts2 比较总结

    原链接:http://blog.csdn.net/chenleixing/article/details/44570681 个人整理: 1.级别不同:SpringMVC :方法  Struts是 类级 ...

  6. grails2.3.11第二课

    第二课主要介绍grails相关插件的使用,这是敏捷开发所必需的途径. 可以把grails的插件看作是grails正常项目的迷你型,因为看插件的源码,它的目录结构和正常项目相差无几. 官方开源插件地址 ...

  7. HW6.1

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  8. algorithm@ O(3/2 n) time to findmaximum and minimum in a array

    public static int[] max_min(int[] a){ //res[0] records the minimum value while res[1] records the ma ...

  9. SSH权威指南(转载)

    本书是一本介绍通信安全的书籍,如果你想保障你的通信安全,本书能给你一个很好的解决方案.本书从ssh协议介绍起,到具体的开源实现和商业实现.但本书同时介绍开源实现和商业实现,给人感觉比较乱.注意:由于o ...

  10. Hadoop MapReduce概念学习系列之mr的Shuffle(二十二)

    Shuffle是非常非常非常重要.搞mr,必须熟烂于心. 因为,分区,分组,排序,,,都是在Shuffle里完成.