现在的位置: 首页 > 综合 > 正文

poj 2584 T-Shirt Gumbo(最大流 s…

2018年03月17日 ⁄ 综合 ⁄ 共 1208字 ⁄ 字号 评论关闭
题意:有xn个参赛者,给出每个参赛者所需要的衣服的尺码的大小范围,在该尺码范围内的衣服该选手可以接受,给出这5种型号衣服各自的数量,问是否存在一种分配方案使得每个选手都能够拿到自己尺码范围内的衣服. 

思路:最大流 建立超级源点src 与5种衣服相连 边权为衣服的数量 超级汇点与xn个人相连 边权为1
然后每个人与自己相应的尺码间也建立一条边,边权为1 求最大流 等于 xn 就输出  T-shirts rock!
反之 I'd rather not wear a shirt anyway...

下面代码很怪,用codeblocks 运行不出来正确答案 用vc就OK 啥原因不明。。。。 = =||

//388K   
0MS
#include <stdio.h>
#include <string.h>
#define VM 30
#define EM 300
const int inf = 0x3f3f3f3f;
struct E
{
    int
to,cap,nxt;
} edge[EM];

int head[VM],dep[VM],cur[VM],pre[VM],gap[VM];
int e,N,x,src,des;

void addedge (int cu,int cv,int cw)
{
    edge[e].to =
cv;
    edge[e].cap
= cw;
    edge[e].nxt
= head[cu];
    head[cu] = e
++;
    edge[e].to =
cu;
    edge[e].cap
= 0;
    edge[e].nxt
= head[cv];
    head[cv] = e
++;
}
void Init() 建图
{
    int
i,x1,x2,num;
    char
s2[5];
    scanf
("%d",&x);    
//x是人数
    src = 0,des
= x + 6;
    N = des +
1;      
//总的点数 两超级点 + xn个人+ 5种型号衣服
    for (i = 1;i
<= x;i ++)
    {
       
scanf ("%s",s2);
       
if (s2[0] == 'S')
           
x1 = x + 1;
       
if (s2[0] == 'M')
           
x1 = x + 2;
       
if (s2[0] == 'L')
           
x1 = x + 3;
       
if (s2[0] == 'X')
           
x1 = x + 4;
       
if (s2[0] == 'T')
           
x1 = x + 5;
       
if (s2[1] == 'S')
           
x2 = x + 1;
       
if (s2[1] == 'M')
           
x2 = x + 2;
       
if (s2[1] == 'L')
           
x2 = x + 3;
       
if (s2[1] == 'X')
           
x2 = x + 4;
       
if (s2[1] == 'T')
           
x2 = x + 5;

抱歉!评论已关闭.