Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟
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.
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).
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".
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
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.
题意:
给你b数组,f数组 ,构造出a数组满足: bi = fai. 有多组情况输出Ambiguity,一组情况输出它,没有输出impossblie
题解:
我们标记f数组,计数找唯一就是了
//
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const int N=+;
#define maxn 100000+5 int H[N],ans[N],c[N],b[N],f[N];
int main() { int n=read(),m=read();
for(int i=;i<=n;i++) {
scanf("%d",&f[i]);
H[f[i]]++;
c[f[i]]=i;
}
for(int i=;i<=m;i++) {
scanf("%d",&b[i]);
}int f=,siz=,cool=;
for(int i=;i<=m;i++) {
if(H[b[i]]>) f=;
if(H[b[i]]==&&!f) {ans[++siz]=c[b[i]];}
if(H[b[i]]==) cool=;
}
if(cool) {
cout<<"Impossible"<<endl;
}
else if(f) {
cout<<"Ambiguity"<<endl;
}
else {
cout<<"Possible"<<endl;
for(int i=;i<=siz;i+=) {
cout<<ans[i]<<" ";
}
}
return ;
}
代码
Codeforces Round #332 (Div. 2) 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. 二) B. Spongebob and Joke
Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...
- 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 #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #332 (Div. 2)
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...
随机推荐
- SQL基本操作——DROP撤销索引、表以及数据库
DROP撤销索引.表以及数据库 --DROP INDEX 命令删除表格中的索引 DROP INDEX table_name.index_name --DROP TABLE 语句删除表(表的结构.属性以 ...
- C# 字符串的入门
1."@"表示字符串中的"\"不当成转义符. 2.转义符或者特殊处理的一些字符只是针对于代码中直接写出的字符串中,对于程序运行中读取出来的转义符或者特殊处理的字 ...
- Python语言之控制流(if...elif...else,while,for,break,continue)
1.if...elif...else... number = 23 guess = int(input('Enter an integer : ')) if guess == number: prin ...
- WebAPI PUT,DELETE请求404
- python os os.path模块学习笔记
#!/usr/bin/env python #coding=utf-8 import os #创建目录 os.mkdir(r'C:\Users\Silence\Desktop\python') #删除 ...
- (转) 分布式文件存储FastDFS(一)初识FastDFS
http://blog.csdn.net/xingjiarong/article/details/50559849 一.FastDFS简介 FastDFS是一款开源的.分布式文件系统(Distribu ...
- 浅谈animation里的forwards
forwards可译为向前走, animation-fill-mode(动画填充模式),定义动画播放时间之外的状态 顾名思义,就是在动画播放完了之后给它一个状态 animation-fill-mode ...
- 6 个 Linux 运维典型问题,大牛的分析解决思路在这里
作为一名合格的 Linux 运维工程师,一定要有一套清晰.明确的解决故障思路,当问题出现时,才能迅速定位.解决问题,这里给出一个处理问题的一般思路: 重视报错提示信息:每个错误的出现,都是给出错误提示 ...
- char如何储存3个字节或者4个字节
1.char字符存储的是Unicode编码的代码点,也就是存储的是U+FF00这样的数值,然而我们在调试或者输出到输出流的时候,是JVM或者开发工具按照代码点对应的编码字符输出的. 2. 所以虽然UT ...
- 基本数据类型:布尔型(bool)和空值None
一.布尔型(bool) 布尔类型很简单,就两个值 ,一个True(真),一个False(假), 主要用记逻辑判断: 一件事情成立就是True,不成立就是False,也可以将bool值归类为数字, 是因 ...