Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Created July 8, 2015 06:58
Show Gist options
  • Select an option

  • Save amoshyc/35948513701ceae32c76 to your computer and use it in GitHub Desktop.

Select an option

Save amoshyc/35948513701ceae32c76 to your computer and use it in GitHub Desktop.
Poj 1862: Stripies

Poj 1862: Stripies

分析

這題倒還挺簡單的,但我竟然被 %lf 坑了。

從算幾不等式與題目可知,越大的數需要做越多次開根號,所以要越先被處理。如何找大的數呢?用 priority_queue ~

※ 使用 double 時,scanf%lfprintf%f

AC Code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>

using namespace std;

int N;
priority_queue<double> pq;

double solve() {
    while (pq.size() != 1) {
        double a = pq.top(); pq.pop();
        double b = pq.top(); pq.pop();

        pq.push(2 * sqrt(a * b));
    }

    return pq.top();
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        double inp;
        scanf("%lf", &inp);
        pq.push(inp);
    }

    printf("%.3f\n", solve());

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment