炉石传说 FZU - 2232

https://vjudge.net/problem/FZU-2232 

#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<map>
#include<stack>
#include<string>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const int maxn=2e5+9;
const int mod=1e8+7;

inline ll read()
{
    ll f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

vector<int>g[maxn];
int a[maxn],b[maxn],c[maxn],d[maxn];
bool used[maxn];
int lin[maxn];
int n;
bool ch(int x,int y)
{
    if(a[x]>d[y]&&b[x]>=c[y]) return 1;
    return 0;
}
bool dfs(int u)
{
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(!used[v])
        {
            used[v]=1;
            if(lin[v]==-1||dfs(lin[v]))
            {
                lin[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
int hungary()
{
    int res=0;
    mem(lin,-1);
    for(int u=0;u<n;u++)
    {
        mem(used,0);
        if(dfs(u)) res++;
    }
    return res;
}
int main()
{
    //FASTIO;
    //#define endl '\n'
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
            g[i].clear();
        }
        for(int i=0;i<n;i++)
        {
            cin>>c[i]>>d[i];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(ch(i,j))
                {
                    g[i].push_back(j+n);
                }
            }
        }
        int ans=hungary();
        //cout<<ans<<endl;
        if(ans==n)
        {
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_39132605/article/details/88959409
今日推荐