1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <string> #include <stdio.h> #include <string.h> #include <ctype.h> #include <vector> #include <queue> using namespace std; bool cmp(int a,int b){ return a>b; } int main(){ int caseCnt = 0; scanf("%d",&caseCnt); for (int xxi = 1; xxi <= caseCnt; xxi++) { int n = 0,f= 0; double r[10005]; cin >> n >> f; for (int i = 1; i <= n; i++) { scanf("%lf",&r[i-1]); r[i-1] *= r[i-1]; } f++; sort(r, r+n, cmp); double high = r[0],low = 0; int rf; bool ans = false; double i = (high+low)/2; while (high - low > 0.0000001){ ans = false; i = (high+low)/2; rf = f; for (int q = 1; q <= n; q++) { rf -= (int)(r[q-1]/i); if (rf <= 0) { ans = true; break; } } if (!ans) { high = i; }else{ low = i; } } double pi = asin(1.0) * 2; printf("%.4lfn",i * pi); } return 0; } |
二分的,然后要注意自已还得吃呢,别都给人家了,所以f要+1,然后在hdu上,用long double一定wa,不用想,改成double就好了。
就这样。