zoukankan      html  css  js  c++  java
  • HDU 3729

    求二分图最大完备匹配数和序最大的方案,匈牙利算法解决。

     1 /*
     2 ID:esxgx1
     3 LANG:C++
     4 PROG:hdu3729
     5 */
     6 #include <cstdio>
     7 #include <cstring>
     8 #include <iostream>
     9 #include <stack>
    10 #include <algorithm>
    11 using namespace std;
    12 
    13 #define NSTU    67
    14 #define NRANK    1000009
    15 
    16 
    17 pair<int, int> stu[NSTU];
    18 char visited[NRANK];
    19 int matched[NRANK];
    20 
    21 int aug(int s)
    22 {
    23     for(int t = stu[s].first; t<= stu[s].second; ++t) {
    24         if (!visited[t]) {
    25             visited[t] = 1;
    26             if (matched[t] < 0 || aug(matched[t])) {
    27                 matched[t] = s;
    28                 return 1;
    29             }
    30         }
    31     }
    32     return 0;
    33 }
    34 
    35 int main(void)
    36 {
    37     #ifndef ONLINE_JUDGE
    38     freopen("in.txt", "r", stdin);
    39     #endif
    40 
    41     int T;
    42     for(scanf("%d", &T); T; --T) {
    43         int N;
    44         scanf("%d", &N);
    45         if(!N) {
    46             printf("0
    
    ");
    47             continue;
    48         }
    49         for(int i=0; i<N; ++i) {
    50             int x, y;
    51             scanf("%d%d", &x, &y);
    52             stu[i].first = x, stu[i].second = y;
    53         }
    54 
    55         memset(matched, -1, sizeof(matched));
    56 
    57         int ans[NSTU], _top = 0;
    58         for(int i=N-1; i>0; --i) {
    59             if (aug(i))    ans[_top++] = i+1;
    60             memset(visited, 0, sizeof(visited));
    61         }
    62         if (aug(0))    ans[_top++] = 1;
    63         printf("%d
    ", _top);
    64         while(_top > 1) printf("%d ", ans[--_top]);
    65         if (_top) printf("%d", ans[--_top]);
    66         putchar('
    ');
    67     }
    68     return 0;
    69 }
    2014-09-18 02:17:32 Accepted 3729 484MS 5208K 1225 B G++
  • 相关阅读:
    kubadm初始化找不到镜像
    ssh登录等待时间长问题
    6.vue之v-html
    5.vue之v-text
    4.vue之data对象
    3.vue之el:挂载点
    2.vue基础test
    1.vue之软件VSCode(自动刷新)
    java计算金额保留两位小数精确到分(四舍六入五成双)
    win7 64位 旗舰版装系统记录及window简记
  • 原文地址:https://www.cnblogs.com/e0e1e/p/hdu_3729.html
Copyright © 2011-2022 走看看