洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing
https://daniu.luogu.org/problemnew/show/P1561
题目描述
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 头牛完成旅程的最短时间。
输入输出样例
3
6 4
8 1
2 3
17
#include <cstdio> #define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b) inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
} int Presist()
{
int n,totu=,totd=;
int minu=1e9,mind=1e9; read(n);
for(int ui,di,i=; i<=n; ++i)
{
read(ui),read(di);
totu+=ui,minu=min(minu,ui);
totd+=di,mind=min(mind,di);
}
printf("%d\n",max(totu+mind,totd+minu));
return ;
} int Aptal=Presist();
int main(int arg,char**argv){;}
洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing的更多相关文章
- 洛谷 P1561 [USACO12JAN]爬山Mountain Climbing
		
传送门 题目大意: n头牛,上山时间为u(i),下山为d(i). 要求每一时刻最多只有一头牛上山,一头牛下山. 问每头牛都上下山后花费最少时间. 题解:贪心 推了推样例,发现上山时间一定,那找个下山最 ...
 - P1561 [USACO12JAN]爬山Mountain Climbing
		
P1561 [USACO12JAN]爬山Mountain Climbing 题目描述 Farmer John has discovered that his cows produce higher q ...
 - 洛谷【P1561】[USACO12JAN]爬山Mountain Climbing
		
我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html 题目传送门:https://www.luogu.org/problemn ...
 - [USACO12JAN]爬山Mountain Climbing
		
题目描述 Farmer John has discovered that his cows produce higher quality milk when they are subject to s ...
 - 洛谷P3043 [USACO12JAN]牛联盟Bovine Alliance
		
P3043 [USACO12JAN]牛联盟Bovine Alliance 题目描述 Bessie and her bovine pals from nearby farms have finally ...
 - 洛谷 P1361 小猫爬山
		
题目描述 WD和LHX饲养了N只小猫,这天,小猫们要去爬山.经历了千辛万苦,小猫们终于爬上了山顶,但是疲倦的它们再也不想徒步走下山了. WD和LHX只好花钱让它们坐索道下山.索道上的缆车最大承重量为W ...
 - 洛谷——P1361 小猫爬山
		
https://www.luogu.org/problem/show?pid=1361#sub 题目描述 WD和LHX饲养了N只小猫,这天,小猫们要去爬山.经历了千辛万苦,小猫们终于爬上了山顶,但是疲 ...
 - 洛谷 P3040 [USACO12JAN]贝尔分享Bale Share
		
P3040 [USACO12JAN]贝尔分享Bale Share 题目描述 Farmer John has just received a new shipment of N (1 <= N & ...
 - 洛谷 P3041 [USACO12JAN] Video Game Combos
		
题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...
 
随机推荐
- Pytorch学习(一)—— 自动求导机制
			
现在对 CNN 有了一定的了解,同时在 GitHub 上找了几个 examples 来学习,对网络的搭建有了笼统地认识,但是发现有好多基础 pytorch 的知识需要补习,所以慢慢从官网 API进行学 ...
 - python-matplotlib-lec1
			
接演前文. 设置属性的方法: 使用对象的set_*方法,单独设置每个属性:或使用plt.setp同时设置多个属性 # -*- coding: utf-8 -*- import numpy as np ...
 - pandas-Notes2
			
#coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt dates = pd.date_rang ...
 - debian安装中文字体
			
debian刚安装完成之后,因为没有中文字体,会出现方框. 安装中文字体: $ su # apt-get install fonts-arphic-bkai00mp fonts-arphic-bsmi ...
 - STM8时基单元
			
STM8时基单元 时基单元包含: 16位向上/向下计数器 16位自动重载寄存器 重复计数器 预分频器 (图29:STM8 时基单元) 16位计数器,预分频器,自动重载寄存器和重复计数器寄存器都可以通过 ...
 - 重新造轮子之静态链接2(Static linking)
			
有了上一篇的基础, 这次写一个我们已经滚瓜烂熟的C程序 helloworld .只不过这次我们不能用到到C语言中的main()函数. 实验环境: linux 编译器: gcc 编辑器:Vim 1. ...
 - Django Rest Framework 教程及API向导
			
Django Rest Framework 教程及API向导. 一.请求(Request)REST_FRAMEWORK 中的 Request 扩展了标准的HttpRequest,为 REST_FRAM ...
 - [PDOException]     SQLSTATE[HY000] [2002] No such file or directory
			
编译安装PHP7之后,在安装mysql之后,用pdo操作数据库的时候,出现了此错误[PDOException] SQLSTATE[HY000] [2002] No such file or direc ...
 - [uiautomator篇][1] 官网译文
			
http://www.jianshu.com/p/7718860ec657 2016.07.25 20:59 字数 3675 Android UIAutomator浅谈 --------------- ...
 - AtCoder Regular Contest 064 F - Rotated Palindromes
			
Problem Statement Takahashi and Aoki are going to together construct a sequence of integers. First, ...