问题 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);
}

 



转载于:https://www.cnblogs.com/hao-tian/p/8955152.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值