Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
不是很懂为什么要用优先队列呢?这道题不需要用数据结构来加速啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator