Uva 10883 - Supermean 解题报告(对数)
来源:互联网 发布:软交换网络结构 编辑:程序博客网 时间:2024/04/28 14:12
Supermean
Time Limit: 2 second
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
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.
4110.421.0 2.231 2 351 2 3 4 5
Case #1: 10.400Case #2: 1.600Case #3: 2.000Case #4: 3.000
解题报告: 本人自己WA了好几次,然后看解题报告的。实在很难想到用对数。
公式很容易推出来,每一项为C(n-1, i)*a[i]/2^(n-1)。难点在于n很大,以至于C(n-1, i)和2^(n-1)都很大,无法直接计算。
方法呢也很简单,先用对数处理,再做幂运算还原。对数可以递推。
代码可以改进,可以不开数组,也不用每次都计算log10(2^(n-1)),懒得改了,代码如下:
#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>using namespace std;const int maxn = 55555;double c[maxn], a[maxn];int cas=1;void work(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%lf",a+i); c[0]=0; for(int i=1;i<n;i++) c[i]=c[i-1]+log10(n-i)-log10(i); double ans=0; for(int i=0;i<n;i++) ans+=pow(10.0, c[i]-(n-1)*log10(2))*a[i]; printf("Case #%d: %.3lf\n", cas++, ans);}int main(){ int T; scanf("%d",&T); while(T--) work();}
- Uva 10883 - Supermean 解题报告(对数)
- UVA 10883 Supermean(组合,二项式系数,对数)
- UVa 10883 - Supermean (杨辉三角 通过取对数解决大数除大数)
- UVA 10883 Supermean 上下取对数防溢出
- UVa 10883 Supermean(log压缩)
- UVA - 10883 Supermean
- UVA - 10883 Supermean
- uva 10883 Supermean
- uva 10883——Supermean
- UVa-10883 Supermean(二项式系数)
- UVA 10883 - Supermean(组合数学+数值优化)
- uva 10883 - Supermean(组合数学+数值优化)
- uva 10883 - Supermean( 找规律, log( c(n,m)) )
- Uva 1319 - Maximum 解题报告(数学)
- Uva 1388 Graveyard 解题报告(数学)
- Uva 12124 Assemble 解题报告(二分)
- UVa 1121 Subsequence 解题报告(思维)
- UVa 1422 Processor 解题报告(二分)
- 弹出模式
- C语言中extern的用法(转摘
- 算法 拓扑排序
- 右键菜单修改和调整(注册表)
- EXP-00091和IMP-00010解决办法
- Uva 10883 - Supermean 解题报告(对数)
- zabbix部署proxy
- 秒杀的架构
- 使用循环打印九九乘法表
- 【TJOI2013】循环格
- Zenoss中menu的汉化
- Android JNI知识简介
- 为什么在Spring的配置里,最好不要配置xsd文件的版本号
- 主流视频陷盈利泥沼 聚合类视频App寻第二出路