• 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)


    题目I - Osu! - HDU 5078

    题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值

    #include<stdio.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    
    const int MAXN = 1007;
    const double EPS = 1e-9;
    
    struct Point
    {
        double x, y, time;
    };
    double Dist(Point a, Point b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    int main()
    {
        int T;
    
        scanf("%d", &T);
    
        while(T--)
        {
            int i, N;
            double ans = 0;
            Point p[MAXN];
    
            scanf("%d", &N);
    
            for(i=0; i<N; i++)
            {
                scanf("%lf%lf%lf", &p[i].time, &p[i].x, &p[i].y);
                if(i == 1)
                    ans = Dist(p[i], p[i-1]) / (p[i].time-p[i-1].time);
                else if(i > 1)
                    ans = max(ans, Dist(p[i], p[i-1]) / (p[i].time-p[i-1].time));
            }
    
            printf("%.10f
    ", ans);
        }
    
        return 0;
    }
    View Code

    E - Hatsune Miku - HDU 5074

    题目分析:把前后等于-1的情况分别讨论一下,就是一个简单的dp了.....

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    
    const int MAXN = 107;
    const int oo = 1e9+7;
    
    int main()
    {
        int T;
    
        scanf("%d", &T);
    
        while(T--)
        {
            int i, j, k, N, M;
            int dp[MAXN][MAXN], a[MAXN], val[MAXN][MAXN];
    
            memset(dp, 0, sizeof(dp));
    
            scanf("%d%d", &N, &M);
    
            for(i=1; i<=M; i++)
            for(j=1; j<=M; j++)
                scanf("%d", &val[i][j]);
    
            for(i=1; i<=N; i++)
                scanf("%d", &a[i]);
    
            for(i=N-1; i>0; i--)
            {
                if(a[i] == -1 && a[i+1] == -1)
                {
                    for(j=1; j<=M; j++)
                    for(k=1; k<=M; k++)
                        dp[i][j] = max(dp[i][j], val[j][k]+dp[i+1][k]);
                }
                else if(a[i] == -1)
                {
                    for(j=1; j<=M; j++)
                        dp[i][j] = max(dp[i][j], val[j][a[i+1]]+dp[i+1][a[i+1]]);
                }
                else if(a[i+1] == -1)
                {
                    for(j=1; j<=M; j++)
                        dp[i][a[i]] = max(dp[i][a[i]], val[a[i]][j]+dp[i+1][j]);
                }
                else
                    dp[i][a[i]] = val[a[i]][a[i+1]] + dp[i+1][a[i+1]];
            }
    
            int ans = 0;
    
            for(i=1; i<=M; i++)
                ans = max(ans, dp[1][i]);
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
    View Code

    D - Galaxy - HDU 5073

    题目分析:首先注意输入的是无序....(为此WA一次),题意就是让求去掉K个点后,剩余的点到中心的平方和,中心点计算是 所有数的位置和 / 剩余点数,转变成了求一些数的方差之和,然后化简公式可以发现可以直接计算出来结果,只需要遍历一遍即可(剩余点数一定是连续的,很容易求证)。设剩余点数M,剩余点数的平方和是 sum,剩余点数的位置和是cnt,那么 ans = sum - cnt * cnt / sum, 求出来最小的ans。

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    
    const int MAXN = 1e5+7;
    const int oo = 1e9+7;
    
    double loc[MAXN];
    
    int main()
    {
        int T;
    
        scanf("%d", &T);
    
        while(T--)
        {
            int i, N, M, K;
    
            scanf("%d%d", &N, &K);
    
            for(i=0; i<N; i++)
                scanf("%lf", &loc[i]);
            sort(loc, loc+N);
    
            if(K + 1 >= N)
            {
                printf("0
    ");
                continue;
            }
    
            M = N - K;
            double cnt=0, ans, sum=0;
    
            for(i=0; i<M; i++)
            {
                cnt += loc[i];
                sum += loc[i]*loc[i];
            }
    
            ans = sum - cnt*cnt/M;
    
            for(i=M; i<N; i++)
            {
                sum = sum + loc[i]*loc[i] - loc[i-M]*loc[i-M];
                cnt = cnt + loc[i] - loc[i-M];
    
                ans = min(ans, sum-cnt*cnt/M);
            }
    
            printf("%.10f
    ", ans);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    03.通过商品课程初心商品信息
    04.支付宝支付流程
    02.创建商品(表)应用(App)
    01.商品模块表结构
    七牛云上传视频
    Django之序列化器
    Django之抽象基类
    权限系统
    python实现简单工厂模式
    01.git基本操作
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4800039.html
Copyright © 2020-2023  润新知