BZOJ1449: [JSOI2009] Team Benefits

Source: Internet
Author: User

"Portal: BZOJ1449" Brief test Instructions:

  in a basketball league, there are N teams, the team's spending is related to their outcome, specifically, the first team of the season total expenditure is ci*x^2+di*y^2,di<=ci. (more wins, more bonuses for players), with x, y showing the team's winning matches this season. Now half of the season, each team scored a[i] victory and B[i] field defeat. And then there's the M game going on. Ask the league team what the minimum total cost is.

The following:

Cost flow

Obviously, it's hard for us to deal with a situation where both teams are affected by the outcome.

So let's start by assuming that each game loses and then builds the side according to the cost of winning.

St Connect to each race, the flow rate is 1, the cost is 0

Each match to two teams, the flow is 1, the cost is 0

Since the beginning assumes that both sides lose, so we have to set the cost + loss cost must be the cost of winning, so get c[i]* (x+1) ^2+d[i]* (y-1) ^2-c[i]*x^2-d[i]*y^2

Simplification gets c[i]*2*x+c[i]-d[i]*2*y+d[i] (x is the number of wins, and Y is the number of lost fields)

Each team to the ED, to even S-edge (s) for the rest of the game this team played the number of times, the cost is c[i]*2*w[i]+c[i]-d[i]*2*l[i]+d[i], the flow of 1, and each side w[i]++,l[i]--, indicating the team's victory situation

Judgment correctness: Because C[i]>=d[i], so when the w[i]++,l[i]--, the edge will become larger, and each time the cost flow to find the augmented road, is sure to find the minimum cost of the augmented road, so will be in accordance with the order, a game to win and lose arrangements

Reference Code:
#include <cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;structnode{intX,y,c,d,next,other; intel; Node () {D=0; }}a[110000];intlen,last[6100];voidInsintXintYintCintd) {    intk1=++len,k2=++Len; a[k1].x=x;a[k1].y=y;a[k1].c=c;a[k1].d=D; A[k1].next=last[x];last[x]=K1; a[k2].x=y;a[k2].y=x;a[k2].c=0; a[k2].d=-D; A[k2].next=last[y];last[y]=K2; A[k1].other=K2; A[k2].other=K1;}intst,ed;intlist[6100];intd[6100];BOOLv[6100];intans;intpos[6100],pre[6100];BOOLSPFA () { for(inti=st;i<=ed;i++) d[i]=999999999; D[ST]=0; memset (V,false,sizeof(v)); V[ST]=true; intHead=1, tail=2; list[1]=St;  while(head!=tail) {        intx=List[head];  for(intk=last[x];k;k=A[k].next) {            inty=a[k].y; if(a[k].c>0&&d[y]>d[x]+a[k].d) {D[y]=d[x]+A[K].D; Pos[y]=x; Pre[y]=K; if(v[y]==false) {V[y]=true; List[tail++]=y; }}} head++; V[X]=false; }    if(d[ed]==999999999)return false; Else return true;}intw[5100],l[5100],c[5100],d[5100];voidFlow () { while(SPFA ()) {ans+=d[ed];  for(intx=ed;x!=st;x=Pos[x]) {A[PRE[X]].C--; A[A[PRE[X]].OTHER].C++; }    }}ints[5100];intMain () {intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%d%d%d%d",&w[i],&l[i],&c[i],&D[i]); intsum=0; St=0; ed=m+n+1; memset (s),0,sizeof(s));  for(intI=1; i<=m;i++)    {        intx, y; scanf ("%d%d",&x,&y); S[X]++;s[y]++; Ins (St,i,1,0); INS (i,x+m,1,0); INS (I,y+m,1,0); L[X]++;l[y]++; }     for(intI=1; i<=n;i++) ans+=c[i]*w[i]*w[i]+d[i]*l[i]*L[i]; //C[i]*2*w[i]+c[i]-d[i]*2*l[i]+d[i]     for(intI=1; i<=n;i++)    {         for(intj=1; j<=s[i];j++) {ins (i+m,ed,1, c[i]*2*w[i]+c[i]-d[i]*2*l[i]+D[i]); W[i]++;l[i]--;    }} Flow (); printf ("%d\n", ans); return 0;}

BZOJ1449: [JSOI2009] Team Benefits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.