HDU 4940 Destroy Transportation system 规律题

答案只有2种情况,所以ans = rand()%2; 
if(ans)puts("happy") else puts("unhappy");


==

想过无源汇的网络流,还是比较麻烦的,然后没往下想。。。

设s点集有一些点,

多加一个点一定是y增加比较快_(:зゝ∠)_

然后设s点集只有一个点

#include <cstdio>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
#define N 205
struct node{
    int to, d, b, nex;
}edge[5005], edge2[5005];
int head[N], edgenum;
void add(int u, int v, int d, int b){
    node E = {v, d, b, head[u]};
    edge[edgenum] = E;
    head[u] = edgenum++;
}
int head2[N], edgenum2;
void add2(int u, int v, int d, int b){
    node E = {v, d, b, head2[u]};
    edge2[edgenum2] = E;
    head2[u] = edgenum2++;
}

void init(){memset(head, -1, sizeof head), edgenum = 0;memset(head2, -1, sizeof head2), edgenum2= 0 ;}
int n, m;
bool work(int x){
    int hehe = 0, gg = 0;
    for(int i = head[x]; ~i; i = edge[i].nex){
        hehe += edge[i].d;
    }
    for(int i = head2[x]; ~i; i = edge2[i].nex){
        gg += edge2[i].d + edge2[i].b;
    }
    return hehe>gg;
}
int main() {
    int T,u,v,a,b, Cas = 1; scanf("%d", &T);
    while(T-- > 0) {
        scanf("%d %d",&n,&m);
        init();
        while(m--) {
            scanf("%d %d %d %d",&u,&v,&a,&b);
            add(u, v, a, b);
            add2(v, u, a, b);
        }
        printf("Case #%d: ",Cas++);
        bool yes = true;
        for(int i = 1; yes && i <= n; i++) {
            if(work(i))
                yes = false;
        }
        yes ? puts("happy"):puts("unhappy");
    }
    return 0;
}
/*
5 5 1
1 1 10
8
1 1 2
2 1 2
3 1 1
3 2 2

2 3 2
1 3 2
3 2 2
3 3 3


*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值