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

Posted Blue233333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BZOJ1727: [Usaco2006 Open]The Milk Queue 挤奶队列相关的知识,希望对你有一定的参考价值。

n<=25000个牛,挤奶两道工序两个人来做,要先第一道工序才能第二道,先第一道工序的牛要先第二道工序,一个人同时最多挤奶一头牛,给每头牛两道工序时间求最少用多长时间。

AC率这么高的题又不会。很好。

看两头牛,第一头A1,B1,第二头A2,B2,要1在前面,除非:

这个化简就是:

按这个排序即可。最后统计答案的时候,记个A的前缀和,从头到尾扫,如果前缀和大于当前时间说明第一个人做了很久使第二个人空闲了,那就把当前时间变成这个前缀和,加上最后一个人的B时间即可。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 //#include<math.h>
 5 #include<algorithm>
 6 #include<iostream>
 7 using namespace std;
 8 
 9 int n;
10 #define maxn 25011
11 struct Node
12 {
13     int a,b;
14     bool operator < (const Node &p) const
15     {return min(p.a,b)>min(p.b,a);}
16 }p[maxn];int sum[maxn];
17 int main()
18 {
19     scanf("%d",&n);
20     for (int i=1;i<=n;i++) scanf("%d%d",&p[i].a,&p[i].b);
21     sort(p+1,p+1+n);
22     sum[0]=0;for (int i=1;i<=n;i++) sum[i]=sum[i-1]+p[i].a;
23     int tot=0;
24     for (int i=1;i<=n;i++)
25     {
26         if (sum[i]>tot) tot=sum[i];
27         tot+=p[i].b;
28     }
29     printf("%d\\n",tot);
30     return 0;
31 }
View Code

 

以上是关于BZOJ1727: [Usaco2006 Open]The Milk Queue 挤奶队列的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ1665 Usaco2006 Open The Climbing Wall

bzoj1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

BZOJ1663: [Usaco2006 Open]赶集

[BZOJ1663] [Usaco2006 Open]赶集(spfa最长路)

bzoj 1688: [Usaco2005 Open]Disease Manangement 疾病管理

BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚