Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不是很懂为什么要用优先队列呢?这道题不需要用数据结构来加速啊

Posted by 10152130110 at 2017-02-25 15:44:32 on Problem 1862
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define MAX_N 105

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    int N;
    double a[MAX_N];
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%lf", &a[i]);
    sort(a, a + N);

    if (N == 1)
        printf("%.3f\n", a[0]);
    else if (N == 2)
        printf("%.3f\n", 2 * sqrt(a[0] * a[1]));
    else
    {
        double ans = 2 * sqrt(a[N - 1] * a[N - 2]);
        for (int i = N - 3; i >= 0; i--)
        {
            ans = 2 * sqrt(ans * a[i]);
        }
        printf("%.3f\n", ans);
    }
    return 0;
}
只用排序一次不就好了吗0.0

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator