「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp
题目描述
Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N <= 1,000) have escaped and gone on a rampage! Each minute a cow is outside the fence, she causes one dollar worth of damage. FJ must visit each cow to install a halter that will calm the cow and stop the damage.
Fortunately, the cows are positioned at distinct locations along a straight line on a road outside the farm. FJ knows the location P_i of each cow i (-500,000 <= P_i <= 500,000, P_i != 0) relative to the gate (position 0) where FJ starts.
FJ moves at one unit of distance per minute and can install a halter instantly. Please determine the order that FJ should visit the cows so he can minimize the total cost of the damage; you should compute the minimum total damage cost in this case.
农夫约翰的牧场围栏上出现了一个洞,有N(1 <= N <= 1,000)只牛从这个洞逃出了牧场。这些出逃的奶牛很狂躁,他们在外面到处搞破坏,每分钟每头牛都会给约翰带来1美元的损失。约翰必须用缰绳套住所有的牛,以停止他们搞破坏。
幸运的是,奶牛们都在牧场外一条笔直的公路上,牧场的大门恰好位于公里的0点处。约翰知道每头牛距离牧场大门的距离P_i(-500,000 <= P_i <= 500,000, P_i != 0)
约翰从农场大门出发,每分钟移动一个单位距离,每到一头牛所在的地点,约翰就会给它套上缰绳,套缰绳不花时间。按怎样的顺序去给牛套缰绳才能使约翰损失的费用最少?
输入输出格式
输入格式:
* Line 1: The number of cows, N.
* Lines 2..N+1: Line i+1 contains the integer P_i.
输出格式:
* Line 1: The minimum total cost of the damage.
输入输出样例
说明
Four cows placed in positions: -2, -12, 3, and 7.
The optimal visit order is -2, 3, 7, -12. FJ arrives at position -2 in 2 minutes for a total of 2 dollars in damage for that cow.
He then travels to position 3 (distance: 5) where the cumulative damage is 2 + 5 = 7 dollars for that cow.
He spends 4 more minutes to get to 7 at a cost of 7 + 4 = 11 dollars for that cow.
Finally, he spends 19 minutes to go to -12 with a cost of 11 + 19 = 30 dollars.
The total damage is 2 + 7 + 11 + 30 = 50 dollars.
题解
不知道为什么能蓝。
这是一类被我们机房称为老王关灯的题鬼嘞只有我这么叫
这道题比老王关灯还简单一丢丢,不用算功率啦,
单位时间消耗的dollar直接算未覆盖区间就好啦~
然后这种题 开个long long开不出吃亏开不出上当
还能有效预防越界(QAQ!!!!)
/*
qwerta
P3080 [USACO13MAR]牛跑The Cow Run
Accepted
100
代码 C++,0.81KB
提交时间 2018-09-22 18:59:00
耗时/内存
231ms, 16760KB
*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int dis[];
long long f[][][];
int main()
{
//freopen("a.in","r",stdin);
int n;
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d",&dis[i]);
n++;
sort(dis+,dis+n+);
memset(f,,sizeof(f));
int x=;
for(int i=;i<=n;++i)
if(dis[i]==)x=i;
f[x][x][]=f[x][x][]=;
for(int len=;len<=n;++len)
for(int l=,r=len;r<=n;++l,++r)
{
f[l][r][]=min(f[l+][r][]+(dis[l+]-dis[l])*(n-len+),
f[l+][r][]+(dis[r]-dis[l])*(n-len+));
f[l][r][]=min(f[l][r-][]+(dis[r]-dis[l])*(n-len+),
f[l][r-][]+(dis[r]-dis[r-])*(n-len+));
}
cout<<min(f[][n][],f[][n][]);
return ;
}
「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp的更多相关文章
- 洛谷P3080 [USACO13MAR]牛跑The Cow Run
P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...
- 【bzoj1742】[Usaco2005 nov]Grazing on the Run 边跑边吃草 区间dp
题目描述 John养了一只叫Joseph的奶牛.一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草.我们可以认为草地是一个数轴上的一些点.Joseph看到这些草非常兴奋,它想把它们全部吃 ...
- 众安「尊享e生」果真牛的不可一世么?
近日,具有互联网基因的.亏损大户(成立三年基本没盈利,今年二季度末亏损近4亿,你能指望它多厉害?).财产险公司—众安推出“尊享e生”中高端医疗保险(财险公司经营中高端医疗真的很厉害?真的是中高端医疗险 ...
- 「洛谷P2906」[USACO08OPEN]牛的街区Cow Neighborhoods 解题报告
P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 题目描述 Those Who Know About Cows are aware of the way cows gr ...
- 「kuangbin带你飞」专题十七 AC自动机
layout: post title: 「kuangbin带你飞」专题十七 AC自动机 author: "luowentaoaa" catalog: true tags: - ku ...
- 被「李笑来老师」拉黑之「JavaScript微博自动转发的脚本」
故事的背景如下图,李笑来 老师于10月19日在 知乎Live 开设 一小时建立终生受用的阅读操作系统 的讲座,他老人家看到大家伙报名踊跃,便在微博上发起了一个 猜数量赢取iPhone7 的活动. 因为 ...
- iOS模式详解—「runtime面试、工作」看我就 🐒 了 ^_^.
Write in the first[写在最前] 对于从事 iOS 开发人员来说,当提到 ** runtime时,我想都可以说出来 「runtime 运行时」和基本使用的方法.相信很多开发者跟我当初一 ...
- iOS 模式详解—「runtime面试、工作」看我就 🐒 了 ^_^.
引导 Copyright © PBwaterln Unauthorized shall not be *copy reprinted* . 对于从事 iOS 开发人员来说,所有的人都会答出「runti ...
- 「bzoj1003」「ZJOI2006」物流运输 最短路+区间dp
「bzoj1003」「ZJOI2006」物流运输---------------------------------------------------------------------------- ...
随机推荐
- mysql数据库连接状态,不要做修改数据库表结构的操作;数据库迁移操作;
在开发过程中,python的flask框架使用sqlalmysql连接mysql数据库. 在程序连接数据量过程中,不要修改数据表的结构.比如在连接状态中使用下面的软件修改数据表结构,这个软件立即就会卡 ...
- jmeter源码编译
转载:http://blog.csdn.net/wanglha/article/details/42004943 一.下载源码 git clone git://github.com/apache/jm ...
- sql的一些知识_order by
注释 SELECT name FROM userinfo #这是注释 /* 这是多行注释 */ order by 排序() SELECT username FROM userinfo ORDER BY ...
- git 强制覆盖,分支合并
强制合并 git fetch --all && git reset --hard origin/master && git pull 合并代码 git commit - ...
- Android_自己定义切换控件SwitchView
1.示意图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemltbzIwMTM=/font/5a6L5L2T/fontsize/400/fill/I0JB ...
- android RecycleView复杂多条目的布局
用RecycleView来实现布局形式.默认仅仅能指定一种布局格式.可是实际中我们的布局常常会用到多种类型的布局方式.怎样实现呢? 今天来说下经常使用的2钟方式. 第一种: 通过自己定义addHead ...
- SpringBoot学习之验证信息国际化
以登录为例: 1.controller的登录方法: @RequestMapping("/SSOAuth/login") @ResponseBody public ResponseV ...
- error MSB8011: 未能注冊输出。请尝试启用“逐用户重定向”
初试MFC就遇到困难了.vs2010创建一个MFC ActiveX控件项目. 什么都还没做呢,就出现故障了? 郁闷呀.! ! 1>C:\Program Files\MSBuild\Microso ...
- 几篇QEMU/KVM代码分析文章
QEMU/KVM结合起来分析的几篇文章,代码跟最新的版本有些差异,但大体逻辑一样,写得通俗易懂.我把链接放这里主要是为自己需要查看时调转过去方便,感谢作者的付出! QEMU Source Code S ...
- Hadoop - YARN 概述
一 概述 Apache Hadoop YARN (Yet Another Resource Negotiator,还有一种资源协调者)是一种新的 Hadoop 资源管理器,它是一个通用资源 ...