zoukankan      html  css  js  c++  java
  • [HDOJ1151]Air Raid(最小路径覆盖,匈牙利算法)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1151

    题意:就是求最小路径覆盖,根据定义出的题。

      1 /*
      2 ━━━━━┒ギリギリ♂ eye!
      3 ┓┏┓┏┓┃キリキリ♂ mind!
      4 ┛┗┛┗┛┃\○/
      5 ┓┏┓┏┓┃ /
      6 ┛┗┛┗┛┃ノ)
      7 ┓┏┓┏┓┃
      8 ┛┗┛┗┛┃
      9 ┓┏┓┏┓┃
     10 ┛┗┛┗┛┃
     11 ┓┏┓┏┓┃
     12 ┛┗┛┗┛┃
     13 ┓┏┓┏┓┃
     14 ┃┃┃┃┃┃
     15 ┻┻┻┻┻┻
     16 */
     17 #include <algorithm>
     18 #include <iostream>
     19 #include <iomanip>
     20 #include <cstring>
     21 #include <climits>
     22 #include <complex>
     23 #include <fstream>
     24 #include <cassert>
     25 #include <cstdio>
     26 #include <bitset>
     27 #include <vector>
     28 #include <deque>
     29 #include <queue>
     30 #include <stack>
     31 #include <ctime>
     32 #include <set>
     33 #include <map>
     34 #include <cmath>
     35 using namespace std;
     36 #define fr first
     37 #define sc second
     38 #define cl clear
     39 #define BUG puts("here!!!")
     40 #define W(a) while(a--)
     41 #define pb(a) push_back(a)
     42 #define Rint(a) scanf("%d", &a)
     43 #define Rs(a) scanf("%s", a)
     44 #define Cin(a) cin >> a
     45 #define FRead() freopen("in", "r", stdin)
     46 #define FWrite() freopen("out", "w", stdout)
     47 #define Rep(i, len) for(int i = 0; i < (len); i++)
     48 #define For(i, a, len) for(int i = (a); i < (len); i++)
     49 #define Cls(a) memset((a), 0, sizeof(a))
     50 #define Clr(a, x) memset((a), (x), sizeof(a))
     51 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
     52 #define lrt rt << 1
     53 #define rrt rt << 1 | 1
     54 #define pi 3.14159265359
     55 #define RT return
     56 #define lowbit(x) x & (-x)
     57 #define onecnt(x) __builtin_popcount(x)
     58 typedef long long LL;
     59 typedef long double LD;
     60 typedef unsigned long long ULL;
     61 typedef pair<int, int> pii;
     62 typedef pair<string, int> psi;
     63 typedef pair<LL, LL> pll;
     64 typedef map<string, int> msi;
     65 typedef vector<int> vi;
     66 typedef vector<LL> vl;
     67 typedef vector<vl> vvl;
     68 typedef vector<bool> vb;
     69 
     70 const int maxn = 555;
     71 int nu, nv;
     72 int G[maxn][maxn];
     73 int linker[maxn];
     74 bool vis[maxn];
     75 
     76 bool dfs(int u) {
     77     For(v, 1, nv+1) {
     78         if(G[u][v] && !vis[v]) {
     79             vis[v] = 1;
     80             if(linker[v] == -1 || dfs(linker[v])) {
     81                 linker[v] = u;
     82                 return 1;
     83             }
     84         }
     85     }
     86     return 0;
     87 }
     88 
     89 int hungary() {
     90     int ret = 0;
     91     Clr(linker, -1);
     92     For(u, 1, nu+1) {
     93         Cls(vis);
     94         if(dfs(u)) ret++;
     95     }
     96     return ret;
     97 }
     98 
     99 int n, m;
    100 
    101 int main() {
    102     // FRead();
    103     int T, u, v;
    104     Rint(T);
    105     W(T) {
    106         Cls(G);
    107         Rint(n); Rint(m);
    108         nu = nv = n;
    109         Rep(i, m) {
    110             Rint(u); Rint(v);
    111             G[u][v] = 1;
    112         }
    113         printf("%d
    ", nu - hungary());
    114     }
    115     RT 0;
    116 }
  • 相关阅读:
    移动端获取屏幕的宽度,根据屏幕大小动态设置html的rem字体大小
    解析CSS3伪类选择器nth-of-type和nth-child的用法,以及两者的区别
    移动端的1px的解决方案
    Vue中import from的来源:省略后缀与加载文件夹
    flex布局
    前端开发人员快速创建本地服务器
    centos6.5Xen4.2安装
    centos6.5kvm虚拟化安装部署
    CentOS搭建svn服务器支持https访问
    CentOS6.5搭建LNMP
  • 原文地址:https://www.cnblogs.com/kirai/p/5808146.html
Copyright © 2011-2022 走看看