BZOJ2465: [中山市选2009]小球

Description

给定n个不同颜色的球，每个球都有一个分数，同时有m个瓶子，每个瓶子都有固定的容量。现在，你必须把球放到瓶子里面。请编程计算最多能放多少个球到这些瓶子里。

2 1
2
3
1 2
2 2
4
5
2 4
2 5
0 0

1 2
2 9

HINT

#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i!=-1;i=next[i])
using namespace std;
const int BufferSize=1<<16;
inline char Getchar() {
}
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int inf=1000000000;
const int maxn=510;
const int maxm=20010;
struct ZKW {
int n,m,s,t,inq[maxn],d[maxn];
int first[maxn],next[maxm];
struct Edge {int from,to,flow,cost;}edges[maxm];
ll cost,ans;
void init(int n) {
this->n=n;m=0;
memset(first,-1,sizeof(first));
}
void AddEdge(int u,int v,int w,int cost) {
edges[m]=(Edge){u,v,w,cost};next[m]=first[u];first[u]=m++;
edges[m]=(Edge){v,u,0,-cost};next[m]=first[v];first[v]=m++;
}
int Q[maxn*100],vis[maxn];
int BFS() {
rep(i,1,n) d[i]=inf;d[t]=0;
int l=1,r=0;Q[++r]=t;
while(l<=r) {
int x=Q[l++];inq[x]=0;
ren {
Edge& e=edges[i^1];
if(e.flow&&d[e.from]>d[x]+e.cost) {
d[e.from]=d[x]+e.cost;
if(!inq[e.from]) inq[e.from]=1,Q[++r]=e.from;
}
}
}
rep(i,0,m-1) edges[i].cost+=d[edges[i].to]-d[edges[i].from];
cost+=d[s];return d[s]!=inf;
}
int DFS(int x,int a) {
if(x==t||!a) {ans+=a*cost;return a;}
int f,flow=0;vis[x]=1;
ren {
Edge& e=edges[i];
if(e.flow&&!e.cost&&!vis[e.to]&&(f=DFS(e.to,min(a,e.flow)))) {
e.flow-=f;edges[i^1].flow+=f;
flow+=f;a-=f;if(!a) break;
}
}
return flow;
}
void solve(int s,int t) {
this->s=s;this->t=t;
cost=ans=0;int flow=0,tmp;
while(BFS()) do {
memset(vis,0,sizeof(vis));
flow+=(tmp=DFS(s,inf));
}while(tmp);
printf("%d %lld\n",flow,-ans);
}
}sol;
int A[maxn];
struct Bottle {
int c,q;
bool operator < (const Bottle& ths) const {return q>ths.q;}
}B[maxn];
int main() {
while(1) {
if(!n&&!m) break;
sort(A+1,A+n+1);sort(B+1,B+m+1);
rep(i,1,n) {
int j=1;while(j<=m&&B[j].q>=A[i]) j++;
}
rep(i,1,m) {
}
sol.solve(s,t);
}
return 0;
}
View Code

posted @ 2015-12-10 10:00  wzj_is_a_juruo  阅读(281)  评论(0编辑  收藏  举报