zoukankan      html  css  js  c++  java
  • Codeforces Round #332 (Div. 2)B. Spongebob and Joke

    B. Spongebob and Joke
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai.

    It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively.

    The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≤ fi ≤ n).

    The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≤ bi ≤ n).

    Output

    Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am.

    If there are multiple suitable sequences ai, print "Ambiguity".

    If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible".

    Sample test(s)
    Input
    3 3
    3 2 1
    1 2 3
    Output
    Possible
    3 2 1
    Input
    3 3
    1 1 1
    1 1 1
    Output
    Ambiguity
    Input
    3 3
    1 2 1
    3 3 3
    Output
    Impossible
    Note

    In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.

    In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.

    In the third sample fi ≠ 3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.

    打了好几8次cf了 一直掉到灰名  昨天终于上分了 绿了 关键的一题(纪念翻墙半夜三更打cf的日子)

    题意: 输入 n,m

    第二行 n个整数  f1, f2, ..., fn (1 ≤ fi ≤ n).

    第三行 m个整数  b1, b2, ..., bm (1 ≤ bi ≤ n).

    判断 有且只有一个bi = fai 输出 fai的位置;

    当b 没有在 f出现时输出 Impossible

    当b 在f中出现 但f的位置不唯一时输出Ambiguity

    除此之外 输出 Possible 及b1...bm 对应的位置  看懂题意 代码很简单

    比赛的时候 被hack了一次

    早点睡了 c题要补

    #include<bits/stdc++.h>
    using namespace std;
    map<int,int>mp1;
    map<int,int>mp2;
    map<int,int>mp3;
    int n,m;
    int a,b;
    int s[100005];
    int re[100005];
    int main()
    {
        mp1.clear();
        mp2.clear();
        mp3.clear();
        memset(s,0,sizeof(s));
        memset(re,0,sizeof(re));
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
           {
             scanf("%d",&a);
             mp1[a]++;
             mp2[a]=i+1;
           }
        for(int i=0;i<m;i++)
           {
             scanf("%d",&s[i]);
             mp3[s[i]]=1;
           }
         for(int i=0;i<m;i++)
           {
               if(mp2[s[i]]==0)
               {
                   printf("Impossible
    ");
                   return 0;
               }
               re[i]=mp2[s[i]];
           }
           for(int i=1;i<=n;i++)
               {
                   if(mp1[i]>=2&&mp3[i])
                   {
                       printf("Ambiguity
    ");
                       return 0;
                   }
               }
               printf("Possible
    ");
               printf("%d",re[0]);
               for(int i=1;i<m;i++)
               printf(" %d",re[i]);
               printf("
    ");
        return 0;
    }
    

      

  • 相关阅读:
    Session服务器配置指南与使用经验
    string和byte[]的转换 (C#)
    错误1已授予对“SqlAccess...的友元访问解决方法
    网络视频会议 二
    Editplus配置环境变量
    TSC 条码打印机 Dll 说明
    源码C#事例网址
    C#中的日志类
    分页事例 比较好的
    dotnet 网络编程 tcp
  • 原文地址:https://www.cnblogs.com/hsd-/p/4985119.html
Copyright © 2011-2022 走看看