• 问题 L: Robots


    问题 L: Robots

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 164  解决: 65
    [提交][状态][讨论版][命题人:admin]

    题目描述

    You’re the leading designer of a complex robot, that will explore human unreachable locations. Your job is to design a robot that will go as far as possible. To do this, you have n available energy sources. The ith source is capable of accelerating the robot by a rate of ai (m/s2) and can do this for a total of si seconds. The robot is initially at rest (its initial velocity is zero). 
    You have to decide the order in which to use the sources in order to maximize the total distance traveled by the robot. You will use one source until si seconds have elapsed, then immediately switch to another unused source (the switch is instantaneous). Each source can be used only once.
    Given the accelerations and durations of each source, write an efficient program to determine the optimal order of the sources, in order to maximize the total distance traveled. Your program must compute the difference between the traveled distance in the optimal case and in the default case (the order given by the input data).
    Physics background: if the velocity is v before you start using a source whose acceleration is a then, after t seconds, the robot has traveled a total vt+1/2at2 meters, and the final velocity will be v' = v+at.

    输入

    The input file starts with the number n (1 ≤ n ≤ 104) of sources. Starting from a different line follows the n space-separated acceleration and duration for each source (positive integer numbers).

    输出

    The output file contains the computed difference between the traveled distance in the optimal case and in the default case (the order given by the input data), with one decimal.

    样例输入

    2
    2 1
    30 2
    

    样例输出

    56.0
    ************************************************************************************************************************************
    贪心 水题 只是作为一个记录
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
     
    using namespace std;
     
    struct x
    {
        int a;
        int t;
    };
    int cmp(x p,x q)
    {
        return p.a>q.a;
    }
    int main()
    {
        int n;
        x a[10005];
        x b[10005];
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&a[i].a,&a[i].t);
            b[i].a = a[i].a;
            b[i].t = a[i].t;
        }
        sort(a,a+n,cmp);
     
        double ans = 0;
        double x1 = 0;
        double x2 = 0;
        double v1 = 0;
        double v2 = 0;
        for(int i=0;i<n;i++)
        {
            x1 = v1*a[i].t+(1.0/2)*(a[i].a)*(a[i].t)*(a[i].t);
            v1 = v1+a[i].a * a[i].t;
            x2 = v2*b[i].t+(1.0/2)*(b[i].a)*(b[i].t)*(b[i].t);
            v2 = v2+b[i].a * b[i].t;
            ans+= x1-x2;  //因为看到很多人有wa 怕超限 所以选择每次都见 而不是最后减
        }
        printf("%.1f",ans);
    }


  • 相关阅读:
    JS中怎样获取当前日期的前一个月和后一个月的日期字符串
    JS中怎样将时间字符串转换成Date并比较大小
    Java中判断两个Date时间段是否有交集的方法
    gRPC中Java和node进行异构通信-互为客户端和服务端
    ffmpeg external libraries 下载地址
    libsvtav1 的 qp 和比特率对照表
    libsvtav1 AV1 编码速度比 libaom 大大提升
    ffmpeg windows 最新编译内部版本下载地址变更
    解开获取 aria2c 帮助信息的误区
    frei0r 过了好几年增加 aech0r 滤镜
  • 原文地址:https://www.cnblogs.com/hao-tian/p/8955152.html
Copyright © 2020-2023  润新知