标签:values mini case ges weight stream display int nim
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 4991 Accepted Submission(s): 1215
Special Judge
有n个点,可以删去k个点,使得公式 I 的值最小。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #include <vector> 8 #include <queue> 9 #include <map> 10 #include <stack> 11 #include <set> 12 using namespace std; 13 typedef long long LL; 14 typedef unsigned long long uLL; 15 #define ms(a, b) memset(a, b, sizeof(a)) 16 #define pb push_back 17 #define mp make_pair 18 #define eps 0.0000000001 19 #define IOS ios::sync_with_stdio(0);cin.tie(0); 20 const LL INF = 0x3f3f3f3f3f3f3f3f; 21 const int inf = 0x3f3f3f3f; 22 const int mod = 1e9+7; 23 const int maxn = 50000+10; 24 double a[maxn]; 25 double sum[maxn]; 26 double sum_pow[maxn]; 27 void solve() 28 { 29 ms(sum, 0);ms(sum_pow, 0); 30 int n, k;scanf("%d%d", &n, &k); 31 for(int i = 1;i<=n;i++) scanf("%lf", &a[i]); 32 sort(a+1, a+1+n); 33 for(int i = 1;i<=n;i++){ 34 sum[i] = sum[i-1] + a[i]; 35 sum_pow[i] = sum_pow[i-1] + a[i]*a[i]; 36 } 37 if(n-k<=1){ 38 printf("0.0000000000\n");return; 39 } 40 double ans = (double)INF; 41 for(int i = n-k;i<=n;i++){ 42 double A = (double)(n-k); 43 double B = -2.0*(sum[i]-sum[i-(n-k)]); 44 double C = sum_pow[i] - sum_pow[i-(n-k)]; 45 double x = -B/(2.0*A); 46 // printf("%f %f %f %f\n", A, B, C, x); 47 // printf("%f\n", A*x*x + B*x + C); 48 49 ans = min(ans, A*x*x + B*x + C); 50 } 51 printf("%.10f\n", ans); 52 return; 53 } 54 int main() { 55 #ifdef LOCAL 56 freopen("input.txt", "r", stdin); 57 // freopen("output.txt", "w", stdout); 58 #endif 59 // IOS 60 int t;scanf("%d", &t); 61 while(t--) 62 solve(); 63 return 0; 64 }
标签:values mini case ges weight stream display int nim
原文地址:http://www.cnblogs.com/denghaiquan/p/7257775.html