贪心。。。我怎么不会QAQ【捂脸熊】

对于1、2两头牛,如果1号牛要排在2号牛前面才能时间更少,则

$$max(A_1 + B_1 + B_2, \ A_1 + A_2 + B_2) \le max(A_2 + B_2 + B_1, \ A_2 + A_1 + B_1) \\ \Leftrightarrow min(A_1, \ B_2) < min(A_2, \ B_1)$$

于是排序以后模拟一下就好了

 /**************************************************************
Problem: 1727
User: rausen
Language: C++
Result: Accepted
Time:48 ms
Memory:1156 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
using namespace std;
const int N = 3e4 + ;
const int inf = 1e9; inline int read(); struct data {
int a, b, k; inline void get() {
a = read(), b = read();
if (a < b) k = a;
else k = inf - b;
} inline bool operator < (const data &d) const {
return k < d.k;
}
} a[N]; int n, ans; int main() {
int i, t1, t2;
n = read();
for (i = ; i <= n; ++i) a[i].get();
sort(a + , a + n + );
for (i = , t2 = ; i <= n; ++i) t2 += a[i].b;
for (i = , t1 = ans = ; i <= n; ++i) {
t1 += a[i].a;
ans = max(ans, t1 + t2);
t2 -= a[i].b;
}
printf("%d\n", ans);
return ;
} inline int read() {
static int x;
static char ch;
x = , ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
}

BZOJ1727 [Usaco2006 Open]The Milk Queue 挤奶队列的更多相关文章

  1. 【bzoj1727】[Usaco2006 Open]The Milk Queue 挤奶队列 贪心

    题目描述 Every morning, Farmer John's N (1 <= N <= 25,000) cows all line up for milking. In an eff ...

  2. BZOJ1727:[Usaco2006 Open]The Milk Queue挤奶队列

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

  3. Queue 先进先出队列的操作

    1.Queue定义 System.Collections.Queue类表示对象的先进先出集合,存储在 Queue(队列) 中的对象在一端插入,从另一端移除. 2.优点 1.能对集合进行顺序处理(先进先 ...

  4. C++数据结构之Queue(队列)

    Queue,队列,和我们日常生活中的队列是同样的规则,"先进先出",从尾入,从首出. Queue,主要有三种基本操作,append(添加元素至队尾):serve(队首元素出列):r ...

  5. python-Day3-set 集合-counter计数器-默认字典(defaultdict) -可命名元组(namedtuple)-有序字典(orderedDict)-双向队列(deque)--Queue单项队列--深浅拷贝---函数参数

    上节内容回顾:C语言为什么比起他语言块,因为C 会把代码变异成机器码Pyhton 的 .pyc文件是什么python 把.py文件编译成的.pyc文件是Python的字节码, 字符串本质是 字符数组, ...

  6. pyhton中的Queue(队列)

    什么是队列? 队列就像是水管子,先进先出,与之相对应的是栈,后进先出. 队列是线程安全的,队列自身有机制可以实现:在同一时刻只有一个线程在对队列进行操作. 存数据,取数据 import Queue q ...

  7. STL --> queue单向队列

    queue单向队列 queue 模板类的定义在<queue>头文件中.与stack 模板类很相似,queue 模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器 ...

  8. STL - queue(队列)

    Queue简介 queue是队列容器,是一种"先进先出"的容器. queue是简单地装饰deque容器而成为另外的一种容器. #include <queue> queu ...

  9. Queue<T>队列与Stack<T>堆栈

    一.概述: Queue<T>队列,对象的先进先出集合("FIFO").Stack<T>栈,对象的后进先出集合("LIFO"). Queu ...

随机推荐

  1. C#中实现多继承的方法

    有一个类叫老虎,还有一个类叫苍蝇.现在新创一个超级老虎类,一种可以飞的老虎,超级老虎由于同时也继承自苍蝇 namespace Interface { //飞的接口 public interface I ...

  2. iOS : 静态库制作

    一.静态库简介 1. 什么是库? 库 就是程序代码的集合, 是共享程序代码的一种方式 2. 库的分类? 开源库 公开源代码, 能看到具体实现 例如MJExtension, MJRefresh, AFN ...

  3. DB2常识

    1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ...

  4. placeholder在ie浏览器里不显示的问题解决

    <script type="text/javascript"> if( !('placeholder' in document.createElement('input ...

  5. javascript中怎么让一个页面执行多个window.onload?

    我们都知道在javascript中window.onload 只能有一个如果有多个的话后面的会覆盖前面的,今天我们来看看怎么让一个页面执行多个window.onload <script type ...

  6. 高处胜寒 php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法

    <?php /* * 经典的概率算法, * $proArr是一个预先设置的数组, * 假设数组为:array(100,200,300,400), * 开始是从1,1000 这个概率范围内筛选第一 ...

  7. Linux GDB Debug

    http://blog.jobbole.com/107925/ gdb 调试入门,大牛写的高质量指南 http://blog.jobbole.com/107759/ gdb是the GNU Debug ...

  8. 题目:在泛型为Integer的容器内添加一个字符串.

    这个题目有两种解法,第一种利用反射来解决: //ArrayList<Integer> list = new ArrayList<Integer>(); //在这个泛型为Inte ...

  9. golang csv,xls,xlsx

    要用到的包: "golang.org/x/text/encoding/simplifiedchinese"    "golang.org/x/text/transform ...

  10. Yii2.0 依赖注入(DI)和依赖注入容器的原理

    依赖注入和依赖注入容器 为了降低代码耦合程度,提高项目的可维护性,Yii采用多许多当下最流行又相对成熟的设计模式,包括了依赖注入(Denpdency Injection, DI)和服务定位器(Serv ...