I:点击打开链接
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
double dis = 0;
int T;
cin >>T;
while(T--)
{
int n;
cin >> n;
double t1, x1, y1;
double t, x, y;
dis = 0;
for(int i = 0; i < n; ++i)
{
if(i==0)
{
cin >> t1 >> x1 >> y1;
}
else
{
cin >> t >> x >> y;
dis = max(dis, sqrt((x-x1) * (x-x1) + (y-y1) * (y-y1)) * 1.0/ (1.0 *(t-t1)));
t1 = t, x1 = x, y1 = y;
}
}
printf("%.10lf\n", dis);
}
return 0;
}
D:点击打开链接
这个题给自己涨了点姿势, 枚举前缀和, 然后这个数学公式也是推得很好呀,自己脑子真是太笨了。。。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 50000 + 5;
double a[maxn];
double sum1[maxn];
double sum2[maxn];
int main()
{
int T;
cin >>T;
while(T--)
{
memset(a,0,sizeof(a));
memset(sum1,0,sizeof(sum1));
memset(sum2,0,sizeof(sum2));
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; ++i) scanf("%lf", &a[i]);
if(n==k)
{
printf("%.9lf\n", 0);
continue;
}
sort(a+1,a+n+1);
for(int i = 1; i <= n; ++i)
{
sum1[i] = sum1[i-1] + a[i];
sum2[i] = sum2[i-1] + a[i] * a[i];
}
double res = 1e20;
//cout << res << endl;
for(int i = 1; i <= k+1; ++i)
{
double x1 = sum2[i+n-k-1] - sum2[i-1];
double x2 = sum1[i+n-k-1] - sum1[i-1];
double tmp = x1 - x2*x2/(n-k);
res = min(res, tmp);
}
printf("%.9lf\n", res);
}
return 0;
}