2014 ACM/ICPC Asia Regional Anshan Online

2014 ACM/ICPC Asia Regional Anshan Online

------解题报告

1.HDOJ 5003

题意:

水题,超级大水题。给你一个数字数组,先降序排序,然后用0.95 ^ (i - 1) * ai 求解。边计算边求和。

代码:

int num[550];
double float_num[55];

void init()
{
    for (int i = 1; i <= 50; ++i)
        float_num[i] = pow(0.95, i - 1);    //先打一张幂方表
}

bool cmp(int A, int B)   
{
    return A > B;    //降序排列
}

int main()
{
#ifdef LOCAL
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif // LOCAL
    init();

    int T;
    int n;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i)
            scanf("%d", &num[i]);

        sort(num + 1, num + n + 1, cmp);

        double sum = 0;

        for (int i = 1; i <= n; ++i)
            sum += float_num[i] * (double)num[i];

        printf("%.10lf\n", sum);
    }
    return 0;
}


你可能感兴趣的:(C++,ACM,解题报告)