zoukankan      html  css  js  c++  java
  • BZOJ 1433: [ZJOI2009]假期的宿舍

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 3265  Solved: 1369
    [Submit][Status][Discuss]

    Description

    Input

    Output

    Sample Input

    1
    3
    1 1 0
    0 1 0
    0 1 1
    1 0 0
    1 0 0

    Sample Output

    ˆ ˆ

    HINT

    对于30% 的数据满足1 ≤ n ≤ 12。
    对于100% 的数据满足1 ≤ n ≤ 50,1 ≤ T ≤ 20。

    Source

    吐槽一下洛谷。。

    明明输出格式错了显示WA。。

    QAQ 改了老半天才知道格式错了

    二分图+网络流

    屠龙宝刀点击就送

    #include <cstring>
    #include <cstdio>
    #include <queue>
    #define N 50000
    using namespace std;
    int T,n,nextt[N],to[N],flow[N],head[N],cnt=1,dep[N],zx[N],ans;
    inline void init()
    {
        cnt=1;
        ans=0;
        memset(head,0,sizeof(head));
        memset(nextt,0,sizeof(nextt));
    }
    inline void ins(int u,int v,int w)
    {
        nextt[++cnt]=head[u];
        to[cnt]=v;
        flow[cnt]=w;
        head[u]=cnt;
    }
    bool bfs(int S,int T)
    {
        for(int i=S;i<=T;++i) dep[i]=-1;
        queue<int>q;
        dep[S]=0;
        q.push(S);
        for(int now;!q.empty();)
        {
            now=q.front();q.pop();
            for(int i=head[now];i;i=nextt[i])
            {
                int v=to[i];
                if(dep[v]==-1&&flow[i])
                {
                    dep[v]=dep[now]+1;
                    if(v==T) return true;
                    q.push(v); 
                }
            }
        }
        return false;
    }
    int dfs(int now,int T,int Limit)
    {
        if(now==T||!Limit) return Limit;
        int ret=0,f;
        for(int i=head[now];i;i=nextt[i])
        {
            int v=to[i];
            if(dep[v]==dep[now]+1&&flow[i]&&(f=dfs(v,T,min(Limit,flow[i]))))
            {
                ret+=f;
                Limit-=f;
                flow[i]-=f;
                flow[i^1]+=f;
                if(!Limit) break;
            }
        }
        if(ret!=Limit) dep[now]=-1;
        return ret;
    }
    int Dinic(int S,int T)
    {
        for(;bfs(S,T);ans-=dfs(S,T,0x3f3f3f3f));
        return ans;
    }
    int Main()
    {
        scanf("%d",&T);
        for(int n,x;T--;)
        {
            init();
            scanf("%d",&n);
            int S=0,T=n*n+1;
            for(int i=1;i<=n;++i)
            {
                scanf("%d",&zx[i]);
                if(zx[i]) ins(i+n,T,1),ins(T,i+n,0);
            }
            for(int i=1;i<=n;++i)
            {
                scanf("%d",&x);
                if((!x&&zx[i])||!zx[i]) ins(S,i,1),ins(i,S,0),ans++;
            }
            for(int i=1;i<=n;++i)
            {
                if(zx[i]) ins(i,i+n,1),ins(i+n,i,0);
                for(int j=1;j<=n;++j)
                {
                    scanf("%d",&x);
                    if(x) ins(i,j+n,1),ins(j+n,i,0);
                }
            }
            if(Dinic(S,T)==0) printf("%c%c%c
    ",94,95,94);
            else printf("%c%c%c
    ",84,95,84);
        }
        return 0;
    }
    int sb=Main();
    int main(int argc,char *argv[]){;}
  • 相关阅读:
    739. Daily Temperatures
    556. Next Greater Element III
    1078. Occurrences After Bigram
    1053. Previous Permutation With One Swap
    565. Array Nesting
    1052. Grumpy Bookstore Owner
    1051. Height Checker
    数据库入门及SQL基本语法
    ISCSI的概念
    配置一个IP SAN 存储服务器
  • 原文地址:https://www.cnblogs.com/ruojisun/p/7610095.html
Copyright © 2011-2022 走看看