洛谷 P1561 [USACO12JAN]爬山Mountain Climbing
题目大意:
n头牛,上山时间为u(i),下山为d(i).
要求每一时刻最多只有一头牛上山,一头牛下山。
问每头牛都上下山后花费最少时间。
题解:贪心
推了推样例,发现上山时间一定,那找个下山最快
的当最后一头山上的牛。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 25009
using namespace std; int n; LL ans;
int hh=; struct Cows{
int u,d;
}c[N]; bool cmp(Cows a,Cows b){
return a.u<b.u;
} int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&c[i].u,&c[i].d);
ans+=c[i].u;hh=min(hh,c[i].d);
}
cout<<ans+hh;
return ;
}
70骗分
发现正解和上面的结论是差不多的。
a、总上山时间大于总下山时间
这说明牛的总上山时间是恒定的,一定要记录答案的。
记录答案的还有最后一头牛的下山时间,所以最终结果是
总上山时间+牛最快的下山时间
b、总下山时间大于总上山时间
这说明牛的下山时间是恒定的,一定要记录答案的。
记录答案的还有一头牛的上山时间,所以最终的结果
是:总下山时间+最快牛的上山时间
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std; int n; LL su,sd,mnu,mnd; int main(){
scanf("%d",&n);
mnu=mnd=;
for(int i=;i<=n;i++){
int up,down;
scanf("%d%d",&up,&down);
su+=up;sd+=down;
if(up<mnu)mnu=up;
if(down<mnd)mnd=down;
}
if(su>sd)cout<<su+mnd;
else cout<<sd+mnu;
// cout<<max(su+mnd,sd+mnu);
return ;
}
洛谷 P1561 [USACO12JAN]爬山Mountain Climbing的更多相关文章
- 洛谷—— P1561 [USACO12JAN]爬山Mountain Climbing
https://daniu.luogu.org/problemnew/show/P1561 题目描述 Farmer John has discovered that his cows produce ...
- 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 ...
随机推荐
- 2018-2019-2 20165114《网络对抗技术》Exp1 逆向与Bof基础
逆向及Bof基础实践 目录 一.实践目标 二.实验操作和步骤 1.直接修改程序机器指令 2.通过构造输入参数,造成BOF攻击. 3.注入Shellcode并执行 三.实验总结 四.实验遇到的错误和问题 ...
- IIS Manager could not load type for module provider 'SharedConfig' that is declared in administration.config
https://support.microsoft.com/en-ie/help/3151973/iis-shared-configuration-feature-requires-all-serve ...
- windchill系统——eclipse与服务器同步数据操作
步骤如下
- linux 分析进程占用CPU过高
重点是查看进程的线程中,哪个线程占用cpu过高,然后用gdb附加到进程,调试线程,看是否有死循环或者死锁等问题,步骤如下: 1 先用ps + grep找出该死的进程pid,比如 1706 2 top ...
- RabbitMQ初体验
这里官方使用的Pom是4.0.2版本 <dependencies> <dependency> <groupId>com.rabbitmq</groupId&g ...
- 基本sql查询语句练习
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 ...
- python递归列出目录及其子目录下所有文件
python递归列出目录及其子目录下所有文件 一.前言 函数的递归,简单来说,就是函数内部调用自己 先举个小例子,求阶乘 def factorial(n): if n == 0: return 1 e ...
- v-model和sync修饰符
场景: 在用vue开发的过程中我们经常会遇到父子组件共用同一变量的情况,那么在这种情况下,我们肯定会想直接 把变量传过来用,因为是双向绑定的所以子组件就会修改这个变量,这样在vue中时会报错的. 问题 ...
- RadioButton实现多选一
RadioButton实现多选一 一.简介 二.RadioButton实现多选一方法 1.将多个RadioButton放在一个RadioGroup里面 <RadioGroup android:i ...
- java reflect反射---Java高级开发必须懂的
理解反射对学习Java框架有很大的帮助,如Spring框架的核心就是使用Java反射实现的,而且对做一些Java底层的操作会很有帮助. 一.Class类的使用 1.万事万物皆对象,( ...