UVa10883 Supermean
来源:互联网 发布:我的衣橱是什么软件 编辑:程序博客网 时间:2024/06/08 09:44
这道题开始没有注意越界问题,当 n = 5000 是取组合数非常大,而 2^n 也非常大,需要用自然对数处理一下才能处理 C(N,K)*A[k]/2^N 的求值,而且取对数的时候要分正负零各种情形考虑,提交了很多次,终于 AC 了。
package UVa10883;import java.util.Scanner;public class Main {public static double solve(double[] v, int len) {long n = len - 1;double lgc = 0, lgd = n*Math.log(2);double sum = 0, f;if ( v[0] > 0 )sum += Math.exp(Math.log(v[0]) + lgc - lgd);else if ( v[0] < 0 )sum -= Math.exp(Math.log(-v[0]) + lgc - lgd);for ( int i=1; i<=n; i++ ) {lgc = lgc + Math.log(n-i+1) - Math.log(i);if ( v[i] > 0 ) {f = Math.log(v[i]) + lgc -lgd;sum += Math.exp(f);} else if ( v[i] < 0 ) {f = Math.log(-v[i]) + lgc -lgd;sum -= Math.exp(f);}}return sum;}public static void main(String[] args) {double[] v = new double[51000];Scanner in = new Scanner(System.in);int N = in.nextInt();for ( int i=0; i<N; i++ ) {int n = in.nextInt();for ( int j=0; j<n; j++ ) {v[j] = in.nextDouble();}double r = solve(v,n);System.out.printf("Case #%d: %.3f%n", i+1, r);}}}
- UVa10883 Supermean
- UVa10883 Supermean
- UVA10883 Supermean
- uva10883 - Supermean 杨辉三角
- uva10883 - Supermean-杨辉三角+log应用
- uva10883
- B - Supermean
- UVA - 10883 Supermean
- 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压缩)
- UVA 10883 - Supermean(组合数学+数值优化)
- UVA 10883 Supermean 上下取对数防溢出
- EXT简单的可编辑表格
- Tokyo Cabinet 的四种数据结构
- vs中数据库的创建及连接
- 用TexturePacker将css图片合并到一个图片中
- javascript:history.go()和History.back()等使用方法
- UVa10883 Supermean
- Hadoop中Partition解析
- Partition List
- C++之模板与泛型编程(上)
- 延时函数
- this.SelectedNode
- 温馨与艰辛
- CodeForces 127D Password
- window.open()、window.location()