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 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 Input
3 3
3 2 1
1 2 3
Possible
3 2 1
3 3
1 1 1
1 1 1
Ambiguity
3 3
1 2 1
3 3 3
Impossible
Hint
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.
题意:给你数组f[]和数组b[]问你是否存在数组a[]使得bi==fai;
题解:三种情况1、数组b中的数字数组f中没有 则输出Impossible 2、数组b中的数字在数组f中重复出现且数组b中的数字都在数组f中输出Ambiguity 3、数组b中的数字都在数组f中且无重复输出Possible以及数组a[]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define LL long long
#define MAX 100100
using namespace std;
int b[MAX],f[MAX];
int a[MAX],vis[MAX];
int main()
{
int n,m,i,j,ans;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++)
{
scanf("%d",&ans);
f[ans]=i;
vis[ans]++;
}
for(i=1;i<=m;i++)
scanf("%d",&b[i]);
int flag=0;
int Flag=0;
for(i=1;i<=m;i++)
{
if(vis[b[i]]==0)
{
flag=1;
break;
}
if(vis[b[i]]>1)
Flag=1;
}
if(flag)
{
printf("Impossible\n");
continue;
}
if(Flag)
{
printf("Ambiguity\n");
continue;
}
for(i=1;i<=m;i++)
a[i]=f[b[i]];
printf("Possible\n");
for(i=1;i<m;i++)
printf("%d ",a[i]);
printf("%d\n",a[m]);
}
return 0;
}
Codeforces Round #332 (Div. 二) B. Spongebob and Joke的更多相关文章
-
Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题
B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...
-
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 standa ...
-
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 standa ...
-
Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟
B. Spongebob and Joke While Patrick was gone shopping, Spongebob decided to play a little trick ...
-
Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
-
Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
-
Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calcula ...
-
Codeforces Round #332 (Div. 2)
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...
-
Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
随机推荐
-
mysql乐观锁总结和实践
乐观锁介绍: 乐观锁( Optimistic Locking ) 相对悲观锁而言,乐观锁假设认为数据一般情况下不会造成冲突,所以在数据进行提交更新的时候,才会正式对数据的冲突与否进行检测,如果发现冲突 ...
-
wex5 开机图片时间长
作用: 控制刚打开图片 时间长 修改config.xml 地址:F:\wex\model\Native\templates\advanced 延迟的时间是在本地app的 config.xml中修改, ...
-
mysql 多表连接
现有表R,S如下: 笛卡尔积 select * from R,S; 结果: 注:不需要任何条件.结果为两张表函数相乘(3x3=9). 自连接 select e.empno,e.ename,m.empn ...
-
MSP430F149学习之路——时钟1
1.看门狗产生方波 #include <msp430x14x.h> void main() { WDTCTL = WDT_MDLY_32; IE1 |= WDTIE; P1DIR |= B ...
-
POJ 1384
求猜存钱罐中至少有多少钱.容易知道金币总的重量,接着背包. #include<cstdio> #include<iostream> using namespace std; # ...
-
转载SSIS中的容器和数据流—举例说明数据转换任务
在上一个随笔中我们熟悉了数据流任务,现在来做一个例子,通过实践学习这些介绍的内容.这个例子从AdventureWorks数据库中取得数据,然后对数据进行聚合,排序,计算产生新列操作并输入到一个.csv ...
-
ORA-07217: sltln: environment variable cannot be evaluated及RMAN-06059
备份脚本: RMAN> run { allocate channel c1 device type disk format '$BACKUP_HOME/level0/level0_%d_%s_% ...
-
android-读取Assets图片资源保存到SD - 随心
public class ReadBitmap { public void readByte(Context c, String name, int indexInt) { byte[] b = nu ...
-
WebView高危接口安全检测
高危]WebView高危接口安全检测共2处详细内容:在Android系统4.3.1~3.0版本,系统webview默认添加了searchBoxJavaBridge_接口,如果未移除该接口可能导致低版本 ...
-
Python学习_argsparse
# -*- coding: utf-8 -*- import argparse args = "-f hello.txt -n 1 2 3 -x 100 -y b -z a -q hello ...