Spongebob and Joke(记录数据地址)
来源:互联网 发布:php json decode 编辑:程序博客网 时间:2024/06/07 20:22
Spongebob and Joke
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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 sequencea1, a2, ..., am of lengthm, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequencef1, f2, ..., fn of lengthn and for each number ai got number bi = fai. To finish the prank he erased the initial sequenceai.
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 integersn andm (1 ≤ n, m ≤ 100 000) — the lengths of sequencesfi andbi respectively.
The second line contains n integers, determining sequencef1, f2, ..., fn (1 ≤ fi ≤ n).
The last line contains m integers, determining sequenceb1, b2, ..., bm(1 ≤ bi ≤ n).
Output
Print "Possible" if there is exactly one sequenceai, such thatbi = fai for alli from 1 tom. Then print m integersa1, a2, ..., am.
If there are multiple suitable sequences ai, print "Ambiguity".
If Spongebob has made a mistake in his calculations and no suitable sequenceai exists, print "Impossible".
Sample Input
3 33 2 11 2 3
Possible3 2 1
3 31 1 11 1 1
Ambiguity
3 31 2 13 3 3
Impossible
Hint
In the first sample 3 is replaced by1 and vice versa, while2 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 alli, so no sequenceai transforms into suchbi and we can say for sure that Spongebob has made a mistake.
给出两个集合,f与d,问是否存在另外一个集合a,使,f[a[i]]=b[i],这两天自学容器,初次试手
#include<stdio.h>#include<algorithm>#include<iostream>#include<map>using namespace std;int f[100005],b[100005];int main(){map<int,int>k1;//定义map容器map<int,int>k2;k1.clear();k2.clear();int n,m,x;int sum=0,num=0;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&f[i]);k1[f[i]]++;//键值k2[f[i]]=i;}//记录位置for(int i=1;i<=m;i++){scanf("%d",&b[i]);if(k1[b[i]]==1)sum++;if(k2[b[i]]==0)num++;}if(num!=0)printf("Impossible\n");if(num==0&&sum<m)printf("Ambiguity\n");if(sum==m){printf("Possible\n");for(int i=1;i<=m;i++){if(k1[b[i]]==1)printf("%d ",k2[b[i]]);}printf("\n");}}
- Spongebob and Joke(记录数据地址)
- Spongebob and Joke
- K - Spongebob and Joke
- Spongebob and Joke
- 【codeforce】Spongebob and Joke
- 599B Spongebob and Joke
- Codeforces #332 B. Spongebob and Joke (思路)
- 【CodeForces】599B - Spongebob and Joke(STL)
- 【CodeForces】599B - Spongebob and Joke(STL)
- Codeforces 599B: Spongebob and Joke(技巧,规律)
- 【Codeforces】-599B-Spongebob and Joke(思维)
- Codeforces 599B Spongebob and Joke 【水题】
- Codeforces 299 B Spongebob and Joke
- codeforces 599B Spongebob and Joke
- Codeforces 599 B Spongebob and Joke
- CodeForces 599B Spongebob and Joke
- CodeForces 599B A - Spongebob and Joke
- CF-599B - Spongebob and Joke
- 全局变量
- 异常和数组
- 基于Python的参考文献生成器1.0
- Hibernate学习笔记----级联属性cascade设置以及集合排序
- Android二维码扫描使用ZXing竖屏拉伸变长闪退扫描区域小等问题
- Spongebob and Joke(记录数据地址)
- 换成Ubuntu系统首先要做的事儿
- shell脚本学习笔记
- Java的全排列
- UVa 1630 串折叠(记忆化搜索)
- iOS_正则表达式整理
- Android传感器学习总结
- mysql更新数据
- Java反射机制