P1561 [USACO12JAN]爬山Mountain Climbing

题目描述

Farmer John has discovered that his cows produce higher quality milk when they are subject to strenuous exercise. He therefore decides to send his N cows (1 <= N <= 25,000) to climb up and then back down a nearby mountain!

Cow i takes U(i) time to climb up the mountain and then D(i) time to climb down the mountain. Being domesticated cows, each cow needs the help of a farmer for each leg of the climb, but due to the poor economy, there are only two farmers available, Farmer John and his cousin Farmer Don. FJ plans to guide cows for the upward climb, and FD will then guide the cows for the downward climb. Since every cow needs a guide, and there is only one farmer for each part of the voyage, at most one cow may be climbing upward at any point in time (assisted by FJ), and at most one cow may be climbing down at any point in time (assisted by FD). A group of cows may temporarily accumulate at the top of the mountain if they climb up and then need to wait for FD's assistance before climbing down. Cows may climb down in a different order than they climbed up.

Please determine the least possible amount of time for all N cows to make the entire journey.

农场主约翰发现他的奶牛剧烈运动后产奶的质量更高,所以他决定让N头(1 <= N <= 25,000)奶牛去附近爬山再返回来。

第i头奶牛用时U(i)爬上山,用时D(i)下山。作为家畜,奶牛们每段路都要有农夫的帮助,可是由于经济疲软,农场里只有两个农夫John和Don。John计划引导奶牛爬山,Don引导奶牛下山。虽然每个奶牛都需要向导,但每段旅途只有一名农夫。所有任何时刻只有一头奶牛爬山也只能有一头奶牛下山,奶牛爬上山后,可以暂时停留在山顶上等待Don的帮助。奶牛上山的顺序和下山的顺序不一定要相同。

请计算出所有N 头牛完成旅程的最短时间。

输入输出格式

输入格式:

第一行,一个整数N

第2 到第N+1 行,每行两个用空格隔开的整数U(i)和D(i)。

(1 <= U(i), D(i) <= 50,000).

输出格式:

一行一个整数,表示所有N 头牛完成旅程的最短时间。

输入输出样例

输入样例#1:

3
6 4
8 1
2 3
输出样例#1:

17

//辩论赛终于要来了(今晚),以后能安心搞OI了。。祝自己好运

先上代码吧,,我也没法很严谨的证明粗来
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> inline int read()
{
int x = 0;char ch = getchar();char c = ch;
while(ch < '0' || ch > '9')c = ch,ch = getchar();
while(ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar();
if(c == '-')x = -1 * x;
return x;
} void wri(int k)
{
if(k)
{
wri(k / 10);
putchar(k % 10 + '0');
}
}
inline void write(int k)
{
if(k < 0) putchar('-'),k = -1 * k;
if(k == 0){putchar('0');return;}
wri(k);
} const int MAXN = 25000 + 10;
const int INF = 0x3f3f3f3f; int n;
int sum1,sum2;
int min1,min2;
int temp1,temp2; int main()
{
n = read();
min1 = min2 = INF;
for(int i = 1;i <= n;i ++)
{
temp1 = read();
temp2 = read();
sum1 += temp1;
sum2 += temp2;
if(min1 > temp1)min1 = temp1;
if(min2 > temp2)min2 = temp2;
}
temp1 = min2 + sum1;
temp2 = min1 + sum2;
if(temp1 < temp2)temp1 = temp2;
write(temp1);
return 0;
}

P1561 [USACO12JAN]爬山Mountain Climbing的更多相关文章

  1. 洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing

    https://daniu.luogu.org/problemnew/show/P1561 题目描述 Farmer John has discovered that his cows produce ...

  2. 洛谷 P1561 [USACO12JAN]爬山Mountain Climbing

    传送门 题目大意: n头牛,上山时间为u(i),下山为d(i). 要求每一时刻最多只有一头牛上山,一头牛下山. 问每头牛都上下山后花费最少时间. 题解:贪心 推了推样例,发现上山时间一定,那找个下山最 ...

  3. 洛谷【P1561】[USACO12JAN]爬山Mountain Climbing

    我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.luogu.org/problemn ...

  4. [USACO12JAN]爬山Mountain Climbing

    题目描述 Farmer John has discovered that his cows produce higher quality milk when they are subject to s ...

  5. BUGKU (Mountain climbing)

    UPX壳,手脱后打不开,可能是在windows10脱壳的缘故吧.放在XP虚拟机上手脱可能会好,但是提示缺少dll.无奈,智能用工具了. 用的这个,感觉蛮好用的. 先打开程序.随便输入一个数,提示err ...

  6. [USACO 12JAN]Mountain Climbing

    Description Farmer John has discovered that his cows produce higher quality milk when they are subje ...

  7. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  8. How to do Mathematics

    著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:匿名用户链接:http://www.zhihu.com/question/30087053/answer/47815698来源 ...

  9. BUGKU-逆向(reverse)-writeup

    目录 入门逆向 Easy_vb Easy_Re 游戏过关 Timer(阿里CTF) 逆向入门 love LoopAndLoop(阿里CTF) easy-100(LCTF) SafeBox(NJCTF) ...

随机推荐

  1. React弹窗组件

    原文地址 小寒的博客 这里的弹窗泛指所有的弹出组件,这些组件不受页面其他UI布局影响,处于DOM结构的顶层,绝对定位在body元素下. 这个特殊性也给它的开发提出了特殊的要求. react新版本中的c ...

  2. JavaScrip中的循环语句

    循环语句 循环语句,也是流程控制语句中不可或缺的一种结构.在 JavaScrip中实现循环的方式有好几个一个来看 1.为什么需要循环 在具体介绍 Javascript中的循环之前,首先我们来明确一个问 ...

  3. Git命令汇总(转)

    转自:http://blog.csdn.net/esrichinacd/article/details/17645951 图片看不清请点击放大

  4. codeforces 1195D2-Submarine in the Rybinsk Sea

    传送门:QAQQAQ 题意:自己看 思路:就是一个类似于数位DP的东西... 统计a[i]数位分解的数在每一位出现的个数,即分两种讨论: 1.位数小于当前j,则j会出现在q+i,而且计算顺序互换会计算 ...

  5. codeforces 1129A2-Toy Train

    传送门:QAQQAQ 题意:有1-n个站点,成环形,有一辆运货车,在这个n个站点之间运输糖果,货车只能按照1->n的方向走,到第n个站的时候,又回到的1,现在告诉你有m个运输任务,从x站点运输一 ...

  6. hive报错( Non-Partition column appears in the partition specification)

    在写及测的过程中发现的,有一些可能需要进一步验证.有时候hive报错位置不一定正确需要多确认 1 FAILED: NullPointerException null 不能用视图作为left outer ...

  7. Kafka在window上安装部署

    1.准备工作   ①jdk 具体自行百度安装jdk,配置好 JAVA_HOME和path, 下载地址:   http://www.oracle.com/technetwork/java/javase/ ...

  8. utils05_git在idea下的操作

    1.idea下将工程添加到本地仓库 1>找到自己的git.exe 2>创建本地的git仓库,将项目放入本地仓库 3> *从本地仓库更新 *提交到本地仓库 *比较版本差异 *丢弃我的修 ...

  9. memcpy 和 memmove

    memcpy 原形为: void *memcpy(void *dest, const void *src, size_t n); 其用于内存空间的拷贝,但是并没有考虑内存重叠问题. memmove原形 ...

  10. Docker学习入门

    Docker简介: Docker 包括三个基本概念 镜像(Image) 容器(Container) 仓库(Repository) 理解了这三个概念,就理解了 Docker 的整个生命周期. Docke ...