zoukankan      html  css  js  c++  java
  • Problem FZU 2232 炉石传说(二分匹配)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2232

    分析:因为是要求所有的学长一次性打败所有的敌人,所以可以看做是匹配问题。构建一个图,G[i][j]=1表示学长在攻击对手后,自己的生命值大于0,对方生命值小于等于0。然后看匹配数是否为n即可。

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    
    using namespace std;
    
    #define met(a, b) memset(a, b, sizeof(a))
    #define maxn 303
    #define INF 0x3f3f3f3f
    const int MOD = 1e9+7;
    
    typedef long long LL;
    int v[maxn], used[maxn], G[maxn][maxn];
    int n;
    
    struct point
    {
        int x, y;
    }a[maxn], b[maxn];
    
    int Hungary(int u)
    {
        for(int i=1; i<=n; i++)
        {
            if(!v[i] && G[u][i])
            {
                v[i] = 1;
                if(!used[i] || Hungary(used[i]))
                {
                    used[i] = u;
                    return 1;
                }
            }
        }
        return 0;
    }
    
    int main()
    {
        int T;
    
        scanf("%d", &T);
        while(T --)
        {
            memset(G, 0, sizeof(G));
    
            scanf("%d", &n);
    
            for(int i=1; i<=n; i++)
                scanf("%d %d", &a[i].x, &a[i].y);
    
            for(int i=1; i<=n; i++)
                scanf("%d %d", &b[i].x, &b[i].y);
    
            for(int i=1; i<=n; i++)///学长
            {
                for(int j=1; j<=n; j++)///对手
                {
                    int p = a[i].x-b[j].y;///学长打对手
                    int q = b[j].x-a[i].y;///对手打学长
    
                    if(p>0 && q<=0)
                        G[i][j] = 1;
                }
            }
    
            memset(used, 0, sizeof(used));
            int ans = 0;
    
            for(int i=1; i<=n; i++)
            {
                memset(v, 0, sizeof(v));
                if(Hungary(i))
                    ans ++;
            }
    
            if(ans == n) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Cayley's Tree Formula & Prufer's Method
    POJ 2262:Goldbach's Conjecture
    The Sieve of Eratosthenes (素数筛选法)
    POJ 2244:Eeny Meeny Moo(稍加变形的约瑟夫问题)
    POJ 1595:Prime Cuts
    iframe标签的使用
    js笔记
    Asp.Net知识点
    Reapte控件的使用
    浮躁十年
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5758577.html
Copyright © 2011-2022 走看看