The problem of dormitory in Luogu p2055 holiday hasn't been solved

Keywords: PHP Google sublime

I haven't been blogging for a long time.

Because it's so konjaku.

What can I do with this konjaku

Today, I finally met a template problem (before that, but it's too konjak)

But... Write code for 5 minutes, debug for 2 hours.

Dividing line: returning to the main topic

This is the common Hungarian algorithm. Almost.

How to do this problem?

1: Learn Hungarian algorithm, no matter what engine you use Google.Baidu.360.sogou.bing.yandex.
There are all vivid examples. I won't repeat them here.

2: learn the basic knowledge of graph theory, and be able to save edges with adjacency table (if you only know adjacency matrix, you can learn it first or read my own and then write it by yourself)

3: to write code is to touch the keyboard with your claws

4: debug, Dalao skips by himself

5: the most important step:

Fight the beast!


       ┌─┐        ┌─┐
   ┌─┘  ┴────┘  ┴─┐
   │                        │
   │         ───         │
   │  ─┬┘        └┬─  │
   │                        │
   │         ─┴─         │
   │                        │
   └──┐            ┌──┘
         │            │
         │            │
         │            │
         │            │
         │            │
         │            │
         │            │
         │            └──────────┐
         │                                  │
         │                                  ├─┐
         │                                  ┌─┘
         │                                  │
         └─┐  ┐  ┌────┬  ┐  ┌──┘
             │─┤─┤        │─┤─┤
             └─┴─┘        └─┴─┘
                           Gods and beasts bless you
                         No BUG in code!

It doesn't look right, but paste it into Notepad or sublime(Dev is OK, too)

It's going to be really cool.

Post code now

#include<bits/stdc++.h>

using namespace std;

inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
inline void write(int x) {if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); }

int u[10001],v[10001],f[10001],N[10001],g[10001];
bool bj[10001],bj2[10001],book[10001];

void add(int x,int y,int z){
    u[z] = x; v[z] = y;

    N[z] = f[x]; f[x] = z;
}

bool find(int x){
    for(int i = f[x];i != -1;i = N[i]){
        int p = v[i];
        if(!book[p]){
            book[p] = 1;
            if(g[p] == 0 || find(g[p])){
                g[p] = x;
                return 1;
            }
        }
    }
    return 0;
}

int main(int argc, char const *argv[])
{
    int yy;
    yy = read();

    while(yy){
        int tt = 0;
        yy--;
        memset(f,-1,sizeof f);
        memset(u,0,sizeof u);
        memset(v,0,sizeof v);
        memset(g,0,sizeof g);
        memset(bj,0,sizeof bj);
        memset(bj2,0,sizeof bj2);

        int m,x,tot = 0;
        m = read();

        for(int i = 1;i <= m;++i) bj[i] = read();
        
        for(int i = 1;i <= m;++i) {
            x = read();
            bj2[i] = x;
            
            if(!bj[i]) bj2[i] = 0;
            if(bj2[i]) tt++;
        }

        for(int i = 1;i <= m;++i){
            for(int j = 1;j <= m;++j){
                x = read();
                if(i > j) continue;

                if(i == j && bj[i])
                    x = 1;
                if(x == 0) continue;
                
                if(bj[j] && !bj2[i]){
        //          cout<<i<<" "<<j<<endl;
                    add(i,m + j,++tot);
                }
                
                if(i == j) continue;
                
                if(bj[i] && !bj2[j]){
        //          cout<<j<<" "<<i<<endl;
                    add(j,m + i,++tot);
                }
            }
        }

        // for(int i = 1;i <= m;++i){
        //  cout<<f[i]<<" "<<N[i]<<endl;
        // }

        int cnt = 0;
        for(int i = 1;i <= m;++i){
            memset(book,0,sizeof book);
            if(find(i)) cnt++;
        }
        
        if(cnt == m - tt) cout<<"^_^"<<"\n";
        else cout<<"T_T"<<"\n";
    }
    return 0;
}

/***
  *        ┌─┐        ┌─┐
  *    ┌─┘  ┴────┘  ┴─┐
  *    │                        │
  *    │         ───         │
  *    │  ─┬┘        └┬─  │
  *    │                        │
  *    │         ─┴─         │
  *    │                        │
  *    └──┐            ┌──┘
  *          │            │
  *          │            │
  *          │            │
  *          │            │
  *          │            │
  *          │            │
  *          │            │
  *          │            └──────────┐
  *          │                                  │
  *          │                                  ├─┐
  *          │                                  ┌─┘
  *          │                                  │
  *          └─┐  ┐  ┌────┬  ┐  ┌──┘
  *              │─┤─┤        │─┤─┤
  *              └─┴─┘        └─┴─┘
  *                            Gods and beasts bless you
  *                          No BUG in code!
  */

Posted by jon2s on Mon, 28 Oct 2019 08:51:07 -0700