日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ-2584 T-Shirt Gumbo 最大流

發布時間:2025/7/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ-2584 T-Shirt Gumbo 最大流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡單構圖,構造一個S流向 S,M,L,X,T,賽事 T1,T2,T2...TN流向匯點T。

代碼如下:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 0x3f3f3f3f
#define MAXN 25
using namespace std;

int N, cap[40][40], flow[40][40], p[40], c[40], S = 0, T = 38;

int hash[130], maxflow;

void init()
{
maxflow = 0;
memset(cap, 0, sizeof (cap));
memset(flow, 0, sizeof (flow));
memset(p, 0xff, sizeof (p));
}

inline int min(int x, int y)
{
return x < y ? x : y;
}

void bfs()
{
int finish = 0, pos;
while (!finish) {
memset(c, 0, sizeof (c));
c[S] = INF;
queue<int>q;
q.push(S);
while (!q.empty()) {
if (c[T]) {
break;
}
pos = q.front();
q.pop();
for (int i = 1; i <= T; ++i) {
if (!c[i] && cap[pos][i] > flow[pos][i]) {
c[i] = min(c[pos], cap[pos][i] - flow[pos][i]);
p[i] = pos;
q.push(i);
}
}
}
maxflow += c[T];
if (!c[T]) {
finish = 1;
continue;
}
pos = T;
while (pos != 0) {
flow[p[pos]][pos] += c[T];
flow[pos][p[pos]] -= c[T];
pos = p[pos];
}
}
}

int main()
{
char op[20], detail[5];
int x;
hash['S'] = 1, hash['M'] = 2, hash['L'] = 3, hash['X'] = 4, hash['T'] = 5;
while (scanf("%s", op), strcmp(op, "ENDOFINPUT")) {
init();
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%s", detail);
for (int j = hash[detail[0]]; j <= hash[detail[1]]; ++j) {
cap[j][5+i] = INF; // 反向邊已經清零
cap[5+i][T] = 1;
}
}
for (int i = 1; i <= 5; ++i) {
scanf("%d", &x);
cap[S][i] = x;
}
scanf("%s", op);
bfs();
if (maxflow == N) {
puts("T-shirts rock!");
}
else {
puts("I'd rather not wear a shirt anyway...");
}
}
return 0;
}



轉載于:https://www.cnblogs.com/Lyush/archive/2012/04/05/2433329.html

總結

以上是生活随笔為你收集整理的POJ-2584 T-Shirt Gumbo 最大流的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。