Usaco 轻轨 贪心

有N（1<=N<=20,000）个站点的轻轨站，有一个容量为C（1<=C<=100）的列车起点在1号站点，终点在N号站点，有K(K<=50,000)组牛群，每组数量为M_i（1<=M_i<=N），行程起点和终点分别为S_i和E_i（1<=S_i < E_i<=N）请　计算最多有多少头牛可以搭乘轻轨。对于每一批牛，可以只上一部分，全上，或者全不上

你难以想象如果最后一句没翻译对我造成了多大打击


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define N 50000+5
using namespace std;
{
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * f;
}
int will[N],n,k,c,now,ans,MAX;
struct group
{
int from ,to ,num;
bool operator < (const group &z )const
{
return from^z.from?from<z.from:to<z.to;
}
void out(int i)
{
printf("group %d from %d to %d  %dcows\n",i,from,to,num);
}
void R()
{
}
}g[N];
void solve(int i)
{
if(now+g[i].num<=c)
{
now+=g[i].num;
will[g[i].to]+=g[i].num;
MAX=max(MAX,g[i].to);
//printf("%d cows have come into the train ,they will get off at %d\n",g[i].num,g[i].to);
return ;
}
else
{
int kk=now+g[i].num-c;
for(int j=MAX;j>g[i].to&&kk>0; j--)
if(will[j])
{
int ll=will[j];
will[j]=max(0,will[j]-kk);
MAX=j;
ll-=will[j];
//printf("%d cows have get off the train at the stop %d  beacuse of %d .\n",ll,j,g[i].from);
kk-=ll;
}
will[g[i].to]+=g[i].num-kk;
//printf("now=%d  %d cows have get on the bus ,they will get off at stop %d\n",now,c-now,g[i].to);
now=c;
MAX=max(MAX,g[i].to);
}
}
int main()
{
//freopen("0.in","r",stdin);
//freopen("01.out","w",stdout);
cin>>k>>n>>c;
for(int i=1;i<=k;++i)g[i].R();
sort(g+1,g+k+1);
//for(int i=1;i<=k;++i)g[i].out(i);
int train=1;
for(int i=1;i<=n;++i)
{
if(will[i])
{
ans+=will[i],now-=will[i];
//printf("%d cows succeed at the stop %d.\n",will[i],i);
will[i]=0;
}
while(g[train].from == i)
{
solve(train);
train++;
}
}
cout<<ans;
}

USACO 1.3 Mixing Milk（贪心）

2014-11-25 19:36:55

【BZOJ4582】【Usaco2016 open】Diamond Collector 贪心

2016-05-01 23:01:27

USACO Ski Course Design 解题报告

2014-10-06 06:49:09

BZOJ1578 USACO 2009 Feb Gold 2.Stock Market

2014-09-18 19:13:06

[BZOJ 4096] Usaco2013 dec Milk Scheduling · 贪心

2015-06-20 23:05:51

【通州爆料】通州台湖一村被征地建设轻轨L2线

2016-08-12 18:16:15

重庆轻轨图-清晰版 重庆轻轨图-清晰版

2009年11月17日 215KB 下载

USACO1.3 修理牛棚 Barn Repair

2016-08-18 17:17:54

[BZOJ1691][Usaco2007 Dec]挑剔的美食家（贪心+splay）

2016-04-27 22:56:36

Usaco 轻轨 贪心