zoukankan      html  css  js  c++  java
  • [BZOJ1694/1742/3074]The Cow Run 三倍经验

    Description

    John养了一只叫Joseph的奶牛。一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草。我们可
    以认为草地是一个数轴上的一些点。Joseph看到这些草非常兴奋,它想把它们全部吃光。于是它开始左右行走,吃
    草。John和Joseph开始的时候站在p位置。Joseph的移动速度是一个单位时间一个单位距离。不幸的是,草如果长
    时间不吃,就会腐败。我们定义一堆草的腐败值是从Joseph开始吃草到吃到这堆草的总时间。Joseph可不想吃太腐
    败的草,它请John帮它安排一个路线,使得它吃完所有的草后,总腐败值最小。John的数学很烂,她不知道该怎样
    做,你能帮她么?

    Input

    * Line 1 : Two space-separated integers: N and L. N<=1000
    * Lines 2..N+1: Each line contains a single integer giving the position P of a clump (1 <= P <= 1,000,000).

    Output

    * Line 1: A single integer: the minimum total staleness Bessie can achieve while eating all the clumps.

    Sample Input

    4 10
    1
    9
    11
    19
    INPUT DETAILS:
    Four clumps: at 1, 9, 11, and 19. Bessie starts at location 10.

    Sample Output

    44
    OUTPUT DETAILS:
    Bessie can follow this route:
    * start at position 10 at time 0
    * move to position 9, arriving at time 1
    * move to position 11, arriving at time 3
    * move to position 19, arriving at time 11
    * move to position 1, arriving at time 29
    giving her a total staleness of 1+3+11+29 = 44. There are other routes
    with the same total staleness, but no route with a smaller one.44
     
     

     
     
    感觉翻译的不太好..但也能看2333.
    发现了三倍经验,但都是权限题2333.
    对于我这种非权限汪很不友好...
    然而凭借三道题成功将yousiki学长刷题量冲到日榜第45...
    虽然不知道干了些什么昨天我日榜第5.玄学我都不知道昨天做了些什么2333;
     
    吐槽结束。
    水水的区间dp秒出思路,,,
    设f[i][j][0/1]表示处理完了i~j区间,现在在左端点/右端点的最小损失。
    于是f[i][j][0] 可以从 f[i+1][j][0/1]转移过来,f[i][j][1] 可以从 f[i][j-1][0/1]转移过来。。
    我也是第一次见区间dp没有枚举k...见识太少了233
     

     
    贴那篇题解呢。。。
    对了注意bzoj3074和另外两个不太一样,从输入可以看出来。
    这里贴bzoj1694的。
    // By BriMon
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    inline int read(){
        int res=0;char ch=getchar();
        while(!isdigit(ch)) ch=getchar();
        while(isdigit(ch)){res=(res<<3)+(res<<1)+(ch^48);ch=getchar();}
        return res;
    }
    
    int n, x;
    int f[1005][1005][2], pos[1005];
    
    int main()
    {
        n = read(), x = read();
        for (int i = 1 ; i <= n ; i ++)
            pos[i] = read();
        sort(pos + 1, pos + 1 + n);
        memset(f, 0x3f, sizeof f);
        for (int i = 1 ; i <= n ; i ++) f[i][i][0] = f[i][i][1] = abs(x - pos[i]) * n;
        for (int len = 2 ; len <= n ; len ++)
        {
            for (int i = 1 ; i <= n ; i ++)
            {
                int j = i + len - 1;
                if (j > n) break;
                f[i][j][0] = min(f[i][j][0], min(f[i+1][j][1] + (n - (j - i)) * (pos[j] - pos[i]), f[i+1][j][0] + (n - (j - i)) * (pos[i+1] - pos[i])));
                f[i][j][1] = min(f[i][j][1], min(f[i][j-1][1] + (n - (j - i)) * (pos[j] - pos[j-1]), f[i][j-1][0] + (n - (j - i)) * (pos[j] - pos[i])));
            }
        }
        printf("%d
    ", min(f[1][n][1], f[1][n][0]));
        return 0;
    }
  • 相关阅读:
    win10补丁导致打印机无法共享
    EdgexGo2.0学习-14 EdgeX2.0 AppService导出到Mqtt
    EdgexGo2.0学习-13 EdgeX2.0 编译Appservice
    winform程序在系统缩放150%时右边留空白问题解决办法
    Linux嵌入式串口转网络
    Win10 磁盘变成文件夹
    Win10下使用Gitblit
    JMeter学习笔记——Web接口测试(webservice)
    jmeter之__RandomFromMultipleVars函数使用详解
    jmeter——参数化——$__RandomFromMultipleVars()函数
  • 原文地址:https://www.cnblogs.com/BriMon/p/9415471.html
Copyright © 2011-2022 走看看