CF599B Spongebob and Joke

思路:

模拟,注意特判。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 int pos[100005], x[100005], y[100005], b[100005], n, m, tmp;
 6 int main()
 7 {
 8     cin >> n >> m;
 9     for (int i = 1; i <= n; i++)
10     {
11         scanf("%d", &tmp);
12         x[tmp]++;
13         pos[tmp] = i;
14     }
15     for (int i = 1; i <= m; i++)
16     {
17         scanf("%d", &b[i]);
18         y[b[i]]++;
19     }
20     bool f1 = true, f2 = true;
21     for (int i = 1; i <= n; i++)
22     {
23         if (y[i] && !x[i])
24         {
25             f1 = false;
26             break;
27         }
28         if (x[i] > 1 && y[i])
29         {
30             f2 = false;
31         }
32     }
33     if (!f1)
34         cout << "Impossible" << endl;
35     else if (!f2)
36         cout << "Ambiguity" << endl;
37     else
38     {
39         cout << "Possible" << endl;
40         for (int i = 1; i <= m; i++)
41         {
42             printf("%d ", pos[b[i]]);
43         }
44         puts("");
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/wangyiming/p/6591504.html