An express train to reveries
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized.

On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 to n inclusive, with each integer representing a colour, wishing for the colours to see in the coming meteor outburst. Two incredible outbursts then arrived, each with n meteorids, colours of which being integer sequences a1, a2, ..., an and b1, b2, ..., bn respectively. Meteoroids' colours were also between 1 and ninclusive, and the two sequences were not identical, that is, at least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

Well, she almost had it all — each of the sequences a and b matched exactly n - 1 elements in Sengoku's permutation. In other words, there is exactly one i (1 ≤ i ≤ n) such that ai ≠ pi, and exactly one j (1 ≤ j ≤ n) such that bj ≠ pj.

For now, Sengoku is able to recover the actual colour sequences a and b through astronomical records, but her wishes have been long forgotten. You are to reconstruct any possible permutation Sengoku could have had on that night.

Input

The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst.

The third line contains n space-separated integers b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of colours in the second meteor outburst. At least one i (1 ≤ i ≤ n) exists, such that ai ≠ bi holds.

Output

Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them.

Input guarantees that such permutation exists.

Examples
input
5
1 2 3 4 3
1 2 5 4 5
output
1 2 5 4 3
input
5
4 4 2 3 1
5 4 5 3 1
output
5 4 2 3 1
input
4
1 1 3 4
1 4 3 4
output
1 2 3 4
Note

In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs.

In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.

题解:

题目描述有一点恶心,先讲一讲题意。

说白了就是给你两个数列a和b,要你找一个数列c,使得c与a和b都最多只有一个不同的数,这就是为什么第二组样例只能有一组解的原因。

思路就是一个一个找a和b相同的数直接放到c中,然后分别试一试两种情况就可以了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<ctime>
#include<stack>
#include<vector>
using namespace std;
int n,a[],b[],c[],vis[];
int cnt1,cnt2,cnt3,cnt4;
int main()
{
int i,j;
scanf("%d",&n);
for(i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(i=; i<=n; i++)
{
scanf("%d",&b[i]);
}
memset(c,-,sizeof(c));
for(i=; i<=n; i++)
{
if(a[i]==b[i])
{
if(!vis[a[i]])
{
c[i]=a[i];
vis[a[i]]=;
}
}
}
for(i=; i<=n; i++)
{
if(c[i]==-)
{
if(!cnt1)cnt1=i;
else
{
cnt2=i;
break;
}
}
}
for(i=; i<=n; i++)
{
if(!vis[i])
{
if(!cnt3)cnt3=i;
else
{
cnt4=i;
break;
}
}
}
if(!cnt2)c[cnt1]=cnt3;
else
{
int ans1=,ans2=;
if(a[cnt1]!=cnt3)ans1++;
if(b[cnt1]!=cnt3)ans1++;
if(a[cnt2]!=cnt4)ans2++;
if(b[cnt2]!=cnt4)ans2++;
if(ans1==&&ans2==)
{
c[cnt1]=cnt3;
c[cnt2]=cnt4;
}
else
{
c[cnt2]=cnt3;
c[cnt1]=cnt4;
}
} for(i=; i<=n; i++)
cout<<c[i]<<' ';
return ;
}

An express train to reveries的更多相关文章

  1. B. An express train to reveries

    B. An express train to reveries time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. Codeforces Round #418 (Div. 2) B. An express train to reveries

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. codeforces 814B.An express train to reveries 解题报告

    题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...

  4. Codeforces - 814B - An express train to reveries - 构造

    http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...

  5. CF814B An express train to reveries

    思路: 模拟,枚举. 实现: #include <iostream> using namespace std; ; int a[N], b[N], cnt[N], n, x, y; int ...

  6. #418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)

    题目链接:http://codeforces.com/contest/814/problem/B 题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 ...

  7. Codeforces Round #418 (Div. 2) A+B+C!

    终判才知道自己失了智.本场据说是chinese专场,可是请允许我吐槽一下题意! A. An abandoned sentiment from past shabi贪心手残for循环边界写错了竟然还过了 ...

  8. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

  9. AtCoder Express(数学+二分)

    D - AtCoder Express Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement In ...

随机推荐

  1. mysql的一些使用操作

    1:如果空闲时间很长导致mysql报错: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last pa ...

  2. [转载]PHP文件解压代码

    来自开源中国:

  3. zoj1654 Place the Robots 二分图最大匹配

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 将每一行的包含空地的区域编号 再将每一列的包含空地的区域编号 然 ...

  4. 利用DNS AAAA记录和IPv6地址传输后门

    0x00 前言 在本文中,我想解释如何在DNS流量中利用IPv6地址(AAAA)记录传输Payload.在我之前的文章中,我解释了如何利用DNS和PTR记录,现在我们将讨论AAAA记录. 本文分为两部 ...

  5. 非阻塞式线程安全列表-ConcurrentLinkedDeque

    一.ConcurrentLinkedDeque public class ConcurrentLinkedDeque<E> extends AbstractCollection<E& ...

  6. 如何实现在Windows上运行Linux程序,附示例代码

    微软在去年发布了Bash On Windows, 这项技术允许在Windows上运行Linux程序, 我相信已经有很多文章解释过Bash On Windows的原理, 而今天的这篇文章将会讲解如何自己 ...

  7. GO的初始简书(一)简介安装

    已经玩了很长一段时间的golang了,做个gopher,下面我将逐步展示各种go语言的开发,从入门开始哦,完全是凭着自己学习和实践的结果展示,如果有说的不对的,请指正. 简介 go语言是由Google ...

  8. 高性能mysql(二)——mysql的存储引擎

    在文件系统中,mysql将每个数据库保存为数据目录下的一个子目录.创建表时,mysql会在子目录下创建一个和表同名的.frm文件保存表的定义.例如创建一个名为mytable的表,mysql会在myta ...

  9. Natas Wargame Level 12 Writeup(文件上传漏洞)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsQAAAChCAYAAADA86lDAAAABHNCSVQICAgIfAhkiAAAIABJREFUeF

  10. SpringMVC中的java.lang.ClassNotFoundException: org.aspectj.weaver.BCException 调试过程记录

    报错原因 上文本描述 java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException at java.lang.Class.getDecl ...