加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

UVa 10883 - Supermean (杨辉三角 通过取对数解决大数除大数)

发布时间:2020-12-14 02:58:53 所属栏目:大数据 来源:网络整理
导读:UVA - 10883 Supermean Time Limit: ?3000MS ? Memory Limit: ?Unknown ? 64bit IO Format: ?%lld %llu Submit ? Status Description Problem F Supermean Time Limit: 2 second "I have not failed. I've just found 10,000 ways that won't work." Thomas

UVA - 10883
Supermean
Time Limit:?3000MS ? Memory Limit:?Unknown ? 64bit IO Format:?%lld & %llu

Submit?Status

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

Source

Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Counting ::? Exercises: Beginner
Root :: Prominent Problemsetters ::? Igor Naverniouk (Abednego)

Status




题意:

给出n个数,每相邻两个数求平均数,得到n-1个数,然后再继续这有求得到n-2个,一直到最后1个数。求这个数


手算一下就知道是二项式系数

ans = C(n-1,i) / (2^(n-1))


但是这里范围特别大,所以需要取对数来算

原理:e^log(e,a) = a?



#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64dn"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lldn"
#define oform1 "%lld"
#endif

#define S64I(a) scanf(iform,&(a))
#define P64I(a) printf(oform,(a))
#define P64I1(a) printf(oform1,(a))
#define REP(i,n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i,n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i,s,t) for(int (i)=(s); (i)<=(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const double PI = (4.0*atan(1.0));

int main() {
    int T;

    scanf("%d",&T);
    for(int kase=1; kase<=T; kase++) {
        int n;
        double lnc = 0;
        double ans = 0;
        scanf("%d",&n);
        double ln2 = (n-1) * log(2.0);
        for(int i=0; i<n; i++) {
            double val;
            scanf("%lf",&val);
            if(val > 0) ans += exp(log(val) + lnc - ln2);
            else ans -= exp(log(-val) + lnc - ln2);
            lnc = lnc + log(n-i-1) - log(i+1);
        }
        printf("Case #%d: %.3lfn",kase,ans);
    }

    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读