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. Can not perform pod install under el capitan (15A279b)

    这个问题在stackoverflow上面有过讨论: Can not perform pod install under el capitan (15A279b) 被采纳的答案为:sudo gem in ...

  2. 让memcached和mysql更好的工作

    这次是Fotolog的经验,传说中比Flickr更大的网站,Fotolog在21台服务器上部署了51个memcached实例,总计有254G缓存空间可用,缓存了多达175G的内容,这个数量比很多网站的 ...

  3. (二)学习C#之内存管理

    一.当你运行你的程序通常都会访问哪些内存空间呢? 电脑自言自语道,“这个人要声明一个整数”或“这个人个方法”或“这个人要创建一个对象” 1.这些信息究竟是存在内存里的什么地方呢? 2.或者说用于描述这 ...

  4. CF GYM 100703A Tea-drinking

    题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...

  5. C# 中的结构类型(struct)

    原文 C# 中的结构类型(struct) 简介 有时候,类中只包含极少的数据,因为管理堆而造成的开销显得极不合算.这种情况下,更好的做法是使用结构(struct)类型.由于 struct 是值类型,是 ...

  6. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.3.1

    Let $A=A_1\oplus A_2$. Show that (1). $W(A)$ is the convex hull of $W(A_1)$ and $W(A_2)$; i.e., the ...

  7. hbase分页查询

    为了广大技术爱好者学习netty,在这里帮新浪微博@nettying宣传下他出版的新书 <netty权威指南>@nettying兄在华为NIO实践多年,这本书是他的技术和经验的一个结晶.N ...

  8. java基础之数据类型转换

    在写java程序时,经常会遇到需要数据类型转换,下面我们来介绍一些一些基本数据类型之间的转换. 1.int,folat,double,boolean,long 转换成字符串,其实很简单只需使用一个函数 ...

  9. PHP 判断协议是否为HTTPS

    if ($_SERVER['HTTPS'] != "on") { echo "This is not HTTPS"; }else{ echo "Thi ...

  10. <转>MySQL性能优化的最佳20+条经验

    http://coolshell.cn/articles/1846.html 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心 ...