SDKD Summer Team Contest E

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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值