我对\(Jhonson\)算法的理解:https://www.cnblogs.com/AKMer/p/9863620.html

题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1727

\(Jhonson\)算法裸题,题目还告诉你如果某头奶牛先于另一头奶牛开始进行第一道工序,那么她开始第二道工序的时间也一定在那一头奶牛之前,可谓非常良心了。

时间复杂度:\(O(nlogn)\)

空间复杂度:\(O(n)\)

代码如下:

#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=25005; int n,ans; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} struct cow {
int a,b; bool operator<(const cow &tmp)const {
return min(a,tmp.b)<min(tmp.a,b);//如果写<=的话莫名RE,求大佬指教。写成<也不影响正确性
}
}p[maxn]; int main() {
n=read();
for(int i=1;i<=n;i++)
p[i].a=read(),p[i].b=read();
sort(p+1,p+n+1);int T=0;
for(int i=1;i<=n;i++) {
ans+=p[i].a;
T=p[i].b+max(T-p[i].a,0);//排完序直接模拟就可以了
}
printf("%d\n",ans+T);
return 0;
}

最新文章

  1. 【转】Linux学习之路--启动VNC服务
  2. Spring mvc-异常javax.servlet.ServletException: Could not resolve view with name &#39;xxx&#39; in servlet with name &#39;spring&#39;
  3. PHP魔术方法以及关于独立实例与相连实例的讲解
  4. 《微信小程序七日谈》- 第二天:你可能要抛弃原来的响应式开发思维
  5. guacamole 0.9.9安装与配置
  6. ExtJS学习之路第一步:对比jQuery,认识ExtJS
  7. cordova 开发属于自己的插件---android
  8. 【百度地图API】发布静态图API啦!只需一个网址,即可展示定制百度地图!
  9. Mybatis增加对象属性不增加mapper.xml的情况
  10. java后端学习流程
  11. 【TCP/IP详解 卷1:协议】 第18章TCP连接的建立与终止
  12. plsql中文乱码问题方案解决
  13. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)
  14. 08_ for 练习 _ sumOf7
  15. APDL link180单元
  16. java技术突破要点
  17. location-alias
  18. python random函数
  19. devexpress 的combobox怎样只能选择不能输入
  20. In-Memory:内存优化表的DMV

热门文章

  1. js arguments对象
  2. [note]CRT&amp;exCRT
  3. Cordova 教程 学习步骤-从零基础开始
  4. 论文解析 &quot;A Non-Local Cost Aggregation Method for Stereo Matching&quot;
  5. FOXMAIL提示容量满无法收邮件,清除旧邮件后还是无法收取,请问如何解决?
  6. redis于spring整合之RedisTemplate
  7. Java多线程系列 JUC线程池05 线程池原理解析(四)
  8. BEM —— 源自Yandex的CSS 命名方法论
  9. 自底向上归并排序(Merge Sort)
  10. 算法(Algorithms)第4版 练习 1.5.12