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. JAVA高级特性 - 注解

    注解是插入到代码中用于某种工具处理的标签.这些标签可以在源码层次上进行操作,或者可以处理编译器将其纳入到注解类文件中. 注解不会改变对程序的编译方式.Java编译器会对包含注解和不包含注解的代码生成相 ...

  2. POJ 3648 Wedding (2-SAT,经典)

    题意:新郎和新娘结婚,来了n-1对夫妻,这些夫妻包括新郎之间有通奸关系(包括男女,男男,女女),我们的目地是为了满足新娘,新娘对面不能坐着一对夫妻,也不能坐着有任何通奸关系的人,另外新郎一定要坐新娘对 ...

  3. linux 下使用 cmake安装mysql

    原文地址:http://www.cppblog.com/issay789/archive/2013/01/05/196967.html 一.安装 m4 下载地址: http://files.w3pc. ...

  4. tomcat+dbcp+jndi 配置

    1)添加jar包 tomcat6中 TOMCAT_HOME/lib 下是公用jar包 dbcp需要3个jar包:Jakarta-Commons DBCP,Jakarta-Commons Collect ...

  5. linux下判断网络是否连接

    本文改写自网上的一个程序,原始程序中为阻塞式调用,而且有现成创建的过程,非常不利于集成到自己程序中,因此对原始程序进行改造,使其可以完成发送一个imcp包的方式来判断网络连通,只需要调用改进后的 bo ...

  6. 基于kryonet的RPC,使用kryo进行序列化

    Kryo是一个序列化框架. Kryonet是一个基于kryo的RPC框架,它实现了一套高效简洁的API,它通过NIO实现了TCP和UDP通讯,目前还不支持Http. 自己写了一个测试代码,运行了下,感 ...

  7. HDU 5694 BD String 递归暴力

    http://blog.csdn.net/angon823/article/details/51484906 #include <cstdio> #include <iostream ...

  8. 怎么解决div覆盖内容却没覆盖的问题?

    一.在上下结构的div布局中,可能出现div覆盖div,但是内容却没有出现覆盖的现象.看看一个示例 1: <!DOCTYPE html> 2: <html> 3: <he ...

  9. MMU(what,how,todo)

    出处:http://www.100ask.org/bbs/forum.php?mod=viewthread&tid=11580&fromuid=5490 正文黑色,代码蓝色,重点标红. ...

  10. 【暑假】[深入动态规划]UVa 12170 Easy Climb

    UVa 12170 Easy Climb 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=24844 思路:  引别人一 ...