HDU 5821 Ball

记录一下每个位置最终到达的位置。然后每次操作排序。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-8;
void File()
{
    freopen("D:\in.txt","r",stdin);
    freopen("D:\out.txt","w",stdout);
}
inline int read()
{
    char c = getchar(); while(!isdigit(c)) c = getchar(); int x = 0;
    while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();  }
    return x;
}

const int maxn=1010;
int T,n,m;
int a[maxn],b[maxn],f[maxn];
struct X{int pos;}s[maxn];

bool cmp(X a,X b){return a.pos<b.pos;}

int main()
{
   // File();
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m); memset(f,0,sizeof f);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=n;i++) scanf("%d",&b[i]);

        int ans=1;
        for(int i=1;i<=n;i++)
        {
            s[i].pos=-1;
            for(int j=1;j<=n;j++)
            {
                if(f[j]) continue;
                if(a[i]!=b[j]) continue;
                s[i].pos=j; f[j]=1; break;
            }
            if(s[i].pos==-1) ans=0;
        }

        for(int i=1;i<=m;i++)
        {
            int L,R; scanf("%d%d",&L,&R);
            sort(s+L,s+R+1,cmp);
        }

        for(int i=1;i<=n;i++) if(s[i].pos!=i) ans=0;

        if(ans) printf("Yes
");
        else printf("No
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5765269.html