UVA - 10883 Supermean
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 |
Case #1: 10.400 |
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的更多相关文章
- 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- ...
- uva - 10833 Supermean(二项式系数,对指数)
模拟发现,每个元素求和时,元素的系数是二项式系数,于是ans=sum(C(n-1,i)*a[i]/2^(n-1)),但是n太大,直接求会溢出,其实double的范围还是挺大的,所以可以将组合数转化成对 ...
- UVa 10883 超级平均数(二项式系数+对数计算)
https://vjudge.net/problem/UVA-10883 题意: 给出n个数,每相邻两个数求平均数,依次类推,最后得到1个数,求该数. 思路: 演算一下可以发现最后各个数的系数就是二项 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- 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 ...
随机推荐
- freemarker 如何获得list的索引值
<#list toplist as toplists> ${toplists_index} </#list> 相当方便
- 【转】Android项目中编译 C的模块
原文网址:http://blog.csdn.net/Harrison_zhu/article/details/4057738 Android编译环境本身比较复杂,且不像普通的编译环境:只有顶层目录下才 ...
- 巧用CSS文件愚人节恶搞(转)
明天就是4月1日愚人节了,也就是那个可适度开玩笑.整蛊的日子了.如果你想和那些要上网的朋友或同事开个极客式玩笑,那就来试试这个国外网友Wes Bos分享的 CSS 文件吧. 一.打开浏览器的 Cust ...
- SQL Server 触发器:表的特定字段更新时,触发Update触发器
create trigger TR_MasterTable_Updateon MasterTableafter updateas if update ([Type])--当Type字段被更新时,才会触 ...
- Codeforces 629C Famil Door and Brackets DP
题意:给你一个由括号组成的字符串,长度为m,现在希望获得一个长度为n(全由括号组成)的字符串,0<=n-m<=2000 这个长度为n的字符串要求有两个性质:1:就是任意前缀,左括号数量大于 ...
- selenium IDE & Remote Control & Webdriver
一直忘记写selenium的开始学习的过程,今天趁五一,天气有雨,写下这文章 1.进入selnium官网,了解selenium1,2,grid的区别.下载c#相关的包(使用c#的人非常少) 2.使用I ...
- Jquery UI的datepicker插件使用方法
原文链接;http://www.ido321.com/375.html Jquery UI是一个非常丰富的Jquery插件,并且UI的各部分插件可以独自分离出来使用,这是其他很多Jquery插件没有的 ...
- Android 依赖注入 ButterKnife 基本使用
ButterKnife 是一个快速 Android View 注入框架,开发者是Jake Wharton,简单的来说,ButterKnife 是用注解的方式替代findViewById和setXXXL ...
- 关于java对象的思考
不可变对象和类 由不可变类创建的对象就是不可变对象,要使一个类成为不可变的,它必须满足下面的需求: 所有数据域都是私有的 没有修改器方法 没有一个访问器的方法,它会返回一个指向可变数据域的引用 看下面 ...
- Sort--快速排序
快速排序 1 public class QuickSort{ 2 3 public static int Partition(int[] a,int low,int high){ 4 int pivo ...