Codeforces Round #332 (Div. 2) B. Spongebob and Joke

题意:若第三行的数在第二行的数中出现过,并且全部为出现1次的,则输出possible,并输出其对应的在第二行中的位置。若出现过两次,则输出 Ambiguity,否则,输出Impossible.
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e5+10;
int a[maxm];
int f[maxm];
int b[maxm];
int vis[maxm];
int vit[maxm];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(vis,0,sizeof(vis));
        memset(vit,0,sizeof(vit));
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&f[i]);
            vis[f[i]]=i;
            vit[f[i]]++;
        }
        for(int i=1; i<=m; i++)
        {
            scanf("%d",&b[i]);
        }
        int cnt=0;
        int ok1=0,ok2=0;
        for(int i=1; i<=m; i++)
        {
            if(!vit[b[i]])
            {
                ok1=1;
            }
            else if(vit[b[i]]>1)
            {
                ok2=1;
            }
            else
            {
                a[cnt++]=vis[b[i]];
            }
        }
        if(ok1)
        {
            printf("Impossible\n");
        }
        else if(ok2)
        {
            printf("Ambiguity\n");
        }
        else
        {
            printf("Possible\n");
            for(int i=0; i<m; i++)
            {
                if(i==0)
                    printf("%d",a[i]);
                else
                    printf(" %d",a[i]);
            }
            printf("\n");
        }
    }
    return 0;
}

你可能感兴趣的:(Codeforces Round #332 (Div. 2) B. Spongebob and Joke)