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 ...
随机推荐
- MVC系列学习(四)-初识Asp.NetMVC框架
注:本文章从伯乐那盗了两张图,和一些文字: 1.MVC设计模式 与 Asp.Net Mvc框架 a.MVC设计模式 MVC设计模式 是一种 软件设计模式,将业务逻辑 与 界面显示 分离,并通过某种方式 ...
- CSS——属性选择器
属性选择器:通过对标签中属性的选择,控制标签. <!DOCTYPE html> <html> <head> <style> div[class*=&qu ...
- CSS——float
float:就是在于布局,首先要介绍的是文档流(标准流),之后是浮动布局. 文档流:元素自上而下,自左而右,块元素独占一行,行内元素在一行上显示,碰到父集元素的边框换行. 浮动布局: 1.float: ...
- 六时出行 App 隐私政策
六时出行 App 隐私政策 本应用尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息.但本应用将以高度的勤勉.审慎义 ...
- 15个最受欢迎的Python开源框架(转)
原文地址:http://blog.jobbole.com/72306/ Django: Python Web应用开发框架 Django 应该是最出名的Python框架,GAE甚至Erlang都有框架受 ...
- java设计模式03装饰者者模式
动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. (1)在不影响其他对象的情况下,以动态.透明的方式给单个 ...
- 【YOLO】实时对象检测使用体验
官网:https://pjreddie.com/darknet/yolo/ 以下全部在服务器上完成,服务器上是有opencv等. 1.安装Darknet git clone https://githu ...
- 深入理解Three.js(WebGL)贴图(纹理映射)和UV映射
本文将详细描述如何使用Three.js给3D对象添加贴图(Texture Map,也译作纹理映射,“贴图”的翻译要更直观,而“纹理映射”更准确.).为了能够查看在线演示效果,你需要有一个兼容WebGL ...
- python socket 接口
一.简介 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求.socket起 ...
- 跳转语句(break、continue)
break语句 在switch条件语句和循环语句中都可以使用break语句.当它出现在switch条件语句中时,作用是终止某个case并跳出switch结构. 当它出现在循环语句中,作用是跳出循环语句 ...