FZU 2232

***题意:求最大匹配是否为n

今天突然想起来吧模板改一下,然而自己得想法不对,WA了有十多次吧,看了一下题解,不需要改,套上模板就行***

#include<stdio.h>
#include<string.h>
#define N 200

struct node
{
    int a, b;
} s1[N], s2[N];

int vis[N], used[N], n, G[N][N];

int Hungary(int u)
{
    if(u==0)
        return 0;
    for(int i=1; i<=n; i++)
    {
        if(!vis[i]&&G[u][i])
        {
            vis[i]=1;
            //int a;
            if(!used[i] || Hungary(used[i]))
            {
                used[i]=u;
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    int T;
    scanf("%d", &T);

    while(T--)
    {
        scanf("%d", &n);
        for(int i=1; i<=n; i++)
            scanf("%d%d", &s1[i].a, &s1[i].b);
        for(int i=1; i<=n; i++)
            scanf("%d%d", &s2[i].a, &s2[i].b);
        memset(used, 0, sizeof(used));
        memset(G, 0, sizeof(G));

        for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(s1[i].b>=s2[j].a&&s1[i].a>s2[j].b)
                G[i][j]=1;
        }

        int cnt=0;
        for(int i=1; i<=n; i++)
        {
            memset(vis, 0, sizeof(vis));
            if(Hungary(i))
                cnt++;
        }
        if(cnt==n)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
时间: 2024-12-20 01:20:51

FZU 2232的相关文章

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

FZU 2150 Fire Game(点火游戏)

p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h2 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 18.0000pt } h3 {

FZU 1096 QS Network

QS Network Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original ID: 1096 64-bit integer IO format: %I64d      Java class name: Main In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS.

FZU 1759 欧拉函数 降幂公式

Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000). Input There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a singl

ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪

FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this boar

FZU 2112 并查集、欧拉通路

原题:http://acm.fzu.edu.cn/problem.php?pid=2112 首先是,票上没有提到的点是不需要去的. 然后我们先考虑这个图有几个联通分量,我们可以用一个并查集来维护,假设有n个联通分量,我们就需要n-1条边把他们连起来. 最后对于每个联通分量来说,我们要使它能一次走完,就是要求他是否满足欧拉通路,也就是这个联通分量中至多有2个度为奇数的点,每多出2个度为奇数的点,就多需要一条边(因为单个连通分量的所有点的度数之和为偶数,所以不可能存在奇数个奇数度数的点). 1 #i

FZU Problem 2102 Solve equation (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2102 Problem Description You are given two positive integers A and B in Base C. For the equation: A=k*B+d We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in

FZU Problem 2104 Floor problem (数学啊 )

题目链接:http://acm.fzu.edu.cn/problem.php?pid=2104 Problem Description In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2. You are given 3 posit

FZU 2105 Digits Count(按位维护线段树)

[题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and一个数 2. [l,r]区间or一个数 3. [l,r]区间xor一个数 4. [l,r]区间查询和 操作数均为小于16的非负整数 [题解] 由于操作数很小,因此我们可以按位维护四棵线段树,表示二进制中的第i位, 对于and操作,只有当and的当前位为0时才对区间有影响,效果是将区间全部变为0, 对