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/problem/B
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
Sample Output
Possible
3 2 1
HINT
题意
给你n个f[i],m个b[i],然后问你能不能找到m个a[i],使得b[i]=f[a[i]]
题解:
暴力存一下这个数在f[i]中出现了多少次,如果没出现就输出impossilbe,如果出现多次,就多解,如果出现一次就输出这个数。(注意impossible的优先级大于多解,这是hack点
注意ai可以等于aj
代码
#include<iostream>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
#define maxn 100005
int a[maxn];
int f[maxn];
int b[maxn];
vector<int> Q[maxn];
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%d",&f[i]);
for(int i=;i<m;i++)
scanf("%d",&b[i]);
for(int i=;i<n;i++)
Q[f[i]].push_back(i);
int flag = ;
for(int i=;i<m;i++)
{
if(Q[b[i]].size()==)
return puts("Impossible");
if(Q[b[i]].size()>)
flag = ;
}
if(flag == )
return puts("Ambiguity");
puts("Possible");
for(int i=;i<m;i++)
printf("%d ",Q[b[i]][]+);
printf("\n");
}
Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题的更多相关文章
- 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. 二) 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) A. Patrick and Shopping 水题
A. Patrick and Shopping Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
随机推荐
- 【转】cocos2d-x Lua
Call custom c++ from Lua cocos2d-x lua binds c++ class, class functions ,enum and some global functi ...
- Java SE 6 新特性: Java DB 和 JDBC 4.0
http://www.ibm.com/developerworks/cn/java/j-lo-jse65/index.html 长久以来,由于大量(甚至几乎所有)的 Java 应用都依赖于数据库,如何 ...
- KindEditor Asp.net
最近在使用KindEditor,其中遇到三个问题: 1.textarea添加 runat="server" 后整个editor在运行的时候不能显示出来,我没找到原因,于是我就把ru ...
- NIS Edit&Nsis打包程序发布(安装和卸载)
转自:http://blog.csdn.net/signjing/article/details/7855855 注意:首选得明确自己需要打包的程序,以及程序需要的dll文件,资源文件等. 1.下载N ...
- Win7远程登录Ubuntu14.04
Quote: http://www.xp74.com/article/news/6083.htm Method: One:vnc连接,实现图形化登录 优点:图形化操作,较第二种方法快 缺点:效率不是最 ...
- 在Lua里写unity游戏笔记
gameobject.GetComponent<Transform>(); 翻译成Lua: gameObject:GetComponent (luanet.ctype (Transform ...
- spring-boot系列:初试spring-boot
部署父工程 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http: ...
- 30 分钟 Java Lambda 入门教程
Lambda简介 Lambda作为函数式编程中的基础部分,在其他编程语言(例如:Scala)中早就广为使用,但在Java领域中发展较慢,直到java8,才开始支持Lambda. 抛开数学定义不看,直接 ...
- html5+css3中的background: -moz-linear-gradient 用法
在CSS中background: -moz-linear-gradient 让网站背景渐变的属性,目前火狐3.6以上版本和google浏览器支持这个属性. background: -moz-linea ...
- 【转】从零开始,让你的框架支持CocoaPods
首先概括一个大概的步骤: 代码上传到Github 创建podspec文件 在Github上创建release版本 注册CocoaPods账号 上传代码到CocoaPods 检验是否上传成功 更新框架版 ...