zoukankan      html  css  js  c++  java
  • Food Delivery ZOJ

    When we are focusing on solving problems, we usually prefer to stay in front of computers rather than go out for lunch. At this time, we may call for food delivery.

    Suppose there are N people living in a straight street that is just lies on an X-coordinate axis. The ith person's coordinate is Xi meters. And in the street there is a take-out restaurant which has coordinates X meters. One day at lunchtime, each person takes an order from the restaurant at the same time. As a worker in the restaurant, you need to start from the restaurant, send food to the N people, and then come back to the restaurant. Your speed is V-1 meters per minute.

    You know that the N people have different personal characters; therefore they have different feeling on the time their food arrives. Their feelings are measured by Displeasure Index. At the beginning, the Displeasure Index for each person is 0. When waiting for the food, the ith person will gain Bi Displeasure Index per minute.

    If one's Displeasure Index goes too high, he will not buy your food any more. So you need to keep the sum of all people's Displeasure Index as low as possible in order to maximize your income. Your task is to find the minimal sum of Displeasure Index.

    Input

    The input contains multiple test cases, separated with a blank line. Each case is started with three integers N ( 1 <= N <= 1000 ), V ( V > 0), X ( X >= 0 ), then N lines followed. Each line contains two integers Xi ( Xi >= 0 ), Bi ( Bi >= 0), which are described above.

    You can safely assume that all numbers in the input and output will be less than 231 - 1.

    Please process to the end-of-file.

    Output

    For each test case please output a single number, which is the minimal sum of Displeasure Index. One test case per line.

    Sample Input

    5 1 0
    1 1
    2 2
    3 3
    4 4
    5 5
     

    Sample Output

    55

    不要把本题想的 过于复杂

    刚看到此题时我一直在想怎么在dp数字中记录当前的已用时间

     当我在思考如何在当前时间和目前的价值之间平衡时

    在看到题解时才明白 其实本题可以不考虑时间

    直接把所有的点全都看成0

    每次在走的过程中我们只需要将每秒的增长的不满意度加上

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    long long dp[1004][1004][2];//0左边 1右边
    long long  sum[1004];
    struct node
    {
        long long b;
        long long x;
    }p[1004];
    int cmp(node p,node  q)
    {
        return p.x<q.x;
    }
    int main()
    {
        long long n,v,x;
        while(~scanf("%lld%lld%lld",&n,&v,&x))
        {
            for(int i=0;i<=n+1;i++)
                for(int j=0;j<=n+1;j++)
                    dp[i][j][0]=dp[i][j][1]=1e18;
            //printf("%lld
    ",dp[1][1]);
    //        for(int i=1;i<=n;i++)
    //            dp[i][i][0]=dp[i][i][1]=0;
            for(int i=1;i<=n;i++)
                scanf("%lld%lld",&p[i].x,&p[i].b);
            n++;
            p[n].x=x;
            p[n].b=0;
            sort(p+1,p+1+n,cmp);
            sum[0]=0;
            for(int i=1;i<=n;i++)
                sum[i]=sum[i-1]+p[i].b;
            int tmp;
            for(int i=1;i<=n;i++)
                if(p[i].x==x) tmp=i;
            dp[tmp][tmp][1]=dp[tmp][tmp][0]=0;
            for(int i=tmp;i<=n;i++)//second->左边 first->右边
            {
                for(int j=tmp;j>=1;j--)
                {//零在左边 一在右边
                    if(i==j) continue;
                    dp[j][i][1]=min(dp[j][i][1], dp[j][i-1][0]+(sum[n]-sum[i-1]+sum[j-1])*(p[i].x-p[j].x) );
                    dp[j][i][1]=min(dp[j][i][1], dp[j][i-1][1]+(sum[n]-sum[i-1]+sum[j-1])*(p[i].x-p[i-1].x) );
    
                    dp[j][i][0]=min(dp[j][i][0], dp[j+1][i][0]+(sum[n]-sum[i]+sum[j])*(p[j+1].x-p[j].x) );
                    dp[j][i][0]=min(dp[j][i][0], dp[j+1][i][1]+(sum[n]-sum[i]+sum[j])*(p[i].x-p[j].x) );
                    //cout<<j<<i<<"*"<<dp[j][i][0]<<" "<<dp[j][i][1]<<endl;
                }
            }
        long long ans=min(dp[1][n][1],dp[1][n][0]);
        printf("%lld
    ",ans*v);
        }
        return 0;
    }
  • 相关阅读:
    2020年“3D视觉工坊”视频号最受欢迎视频 Top 10!
    缓存一致性解决方案杂谈
    Mybatis的@Param注解在多参数时候不写,可以正确执行。
    Redis设计与实现之简单动态字符串
    YApi mac上部署
    拖拽方式生成Vue用户界面
    终于可以愉快的撸Java异步代码了!
    Windows 取证之ShellBags
    初识Fastjson漏洞(环境搭建及漏洞复现)
    mongo-express 远程代码执行漏洞分析
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852270.html
Copyright © 2011-2022 走看看