The K-League (網路流,建圖難),thek-league

來源:互聯網
上載者:User

The K-League (網路流,建圖難),thek-league

                                    The K-League

 

題目:

   給出N給人,兩兩之間進行比賽。現在已經確定第i個人贏得場數和輸的場數,讓你通過其與N-1個之間在進行比賽他是否有可能贏得冠軍。

 

演算法:

  可以知道要讓第i個人獲得冠軍那個其與n-1人的比賽他要都贏。既,他能贏得最大場數為win[i] + a[i][j].如果,這個總的場數都大不了別人的已經確定贏得場數那麼其肯定獲得不了冠軍,是吧?。而對與一場比賽只有兩種結果,要麼i贏要麼j贏。這時候我們就可以想到了如何建圖,即把某兩個人在某一場比賽分別當作一個節點。這裡有顯然的對應關係,即比賽是對應著兩個人的。

 

建圖:

   所以,這時候我們可以想到把起點跟比賽相連,容量為這場比賽的次數,對吧?。

然後,把比賽分別跟著場比賽的兩個人相連,因為這場比賽只跟著兩個人有關係,這也對吧?。

最後,在把每個人與匯點相連,而容量是多少?這裡我們假設現在是第x個人是會得到冠軍的所以我們建圖當然也要圍繞著他會贏的最優結果進行。所以,要讓他儘可能的贏。因此,每個人能贏得最大可能就是tot[x] - win[now]。是吧?。就是當前這人在比賽中能在獲勝的場數不能超過tot[x] - win[now],因為他已超過,就表明x這個人就不是冠軍了。圖就這樣建完了。懂了吧?!

 

#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <cstdio>#include <cstring>using namespace std;const int INF = 1 << 20;const int MAXN = 1000;//////////////////////////////////struct Edge{    int from,to,cap,flow;    Edge(){};    Edge(int _from,int _to,int _cap,int _flow)        :from(_from),to(_to),cap(_cap),flow(_flow){};};vector<Edge> edges;vector<int> G[MAXN];int d[MAXN],cur[MAXN];int N,M,src,sink;///////////////////////////////////////////int a[MAXN][MAXN],w[MAXN];int tot[MAXN];void init(){   src = N * N + N + 2; sink = src + 1;   for(int i = 0;i < sink + 2;++i)     G[i].clear();   edges.clear();}void addEdge(int from,int to,int cap){    edges.push_back(Edge(from,to,cap,0));    edges.push_back(Edge(to,from,0,0));    int sz = edges.size();    G[from].push_back(sz - 2);    G[to].push_back(sz - 1);}bool build(int x){     for(int i = 0;i < N;++i){        for(int j = i + 1;j < N;++j){            addEdge(src,i * N + j,a[i][j]);  //第幾場比賽            addEdge(i * N + j,i + N*N,INF);   //是哪兩個人進行比賽            addEdge(i * N + j,j + N*N,INF);        }     }     int sum = 0;     for(int i = 0;i < N;++i){        if(tot[x] < w[i]){  //當前這個人所有能贏得場數都勝不了別人確定的場數            return false;        }        sum += tot[x] - w[i];        addEdge(i + N*N,sink,tot[x] - w[i]); //最多還可以勝的場數     }     return true;}bool check(){    for(int i = 0;i < (int)G[src].size();++i){        if(G[src][i] & 1) continue;        Edge& e = edges[G[src][i]];        if(e.cap != e.flow)          return false;    }    return true;}///////////////////////////////////////////bool BFS(){    fill(d,d + sink + 2,-1);    queue<int> Q;    d[src] = 0;    Q.push(src);    while(!Q.empty()){        int x = Q.front(); Q.pop();        for(int i = 0;i < (int)G[x].size();++i){            Edge& e = edges[G[x][i]];            if(d[e.to] == -1 && e.cap > e.flow){                d[e.to] = d[x] + 1;                Q.push(e.to);            }        }    }    return d[sink] > 0;}int DFS(int x,int a){    if(x == sink || a == 0)        return a;    int flow = 0,f;    for(int& i = cur[x];i < (int)G[x].size();++i){        Edge& e = edges[G[x][i]];        if(d[e.to] == d[x] + 1 && (f = DFS(e.to,min(a,e.cap - e.flow))) > 0){            e.flow += f;            edges[G[x][i]^1].flow -= f;            flow += f;            a -= f;            if(a == 0) break;        }    }    return flow;}int maxFlow(){   int flow = 0;   while(BFS()){        memset(cur,0,sizeof(cur));        flow += DFS(src,INF);   }   return flow;}//////////////////////////////////////////int main(){    //freopen("Input.txt","r",stdin);     int T;     scanf("%d",&T);     while(T--){        int x;        scanf("%d",&N);        for(int i = 0;i < N;++i)            scanf("%d%d",&w[i],&x);        for(int i = 0;i < N;++i){            tot[i] = w[i];            for(int j = 0;j < N;++j){                scanf("%d",&a[i][j]);                tot[i] += a[i][j];            }        }        bool first = true;        for(int i = 0;i < N;++i){            init();            if(!build(i))               continue;            maxFlow();            if(check()){                if(first)                    printf("%d",i+1);                else                    printf(" %d",i+1);                first = false;            }        }        puts("");     }     return 0;}


 


K-League Rookie of the Year是什?

K-League Rookie of the Year 就是韓國K聯賽年度最佳新人獎,創立於1985年。具體名單如下:
年度 球員 俱樂部
1985 李相潤 浦項原子
1986 韓玄日 蔚山現代
1987 金鑄成 皇家大宇
1988 皇甫官 油公
1989 高正雲 一和天馬
1990 宋周熙 蔚山現代
1991 趙佑碩 一和天馬
1992 申台龍 一和天馬
1993 薑廣熙 皇家大宇
1994 崔龍洙 安陽LG
1995 盧相來 虔南天龍
1996 樸建夏 水原三星
1997 申進元 大田市民
1998 李東國 浦項制鐵
1999 李成宰 富川SK
2000 楊玄章 全北現代
2001 宋鐘國 釜山偶像
2002 李天秀 蔚山現代
2003 鄭祖國 安陽LG
2004 文瑉貴 浦項制鐵
2005 樸周永 FC首爾
2006 廉基勳 全北現代
2007 河太勳 水原三星
2008 李聖阮 FC首爾
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.