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 n inclusive, 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.

解体思路:

由题可知,p中不能有重复的,而且数据必合理,那么只有两种情况:

1. 只在一个下标上不同,这时候只要将a[i]此时的值替换为之前从未在a数组中出现的数字便可;

2.在两个下标上不同,只需交换一次ab即可满足,这时必有两种情况:

(1).a第一个下标代表的数是重复的,此时b必不重复,那么就和b交换,但这时有个特殊情况那就是,和第一个下标重复的正好是第二个下标,进行判断:

如果第一个下标下的代表的数字在a中没出现过那么就交换第一个下标的ab,否则交换第二个下标中的ab;

(2).若a第一个下标代表的数不是重复的,此时只需交换第二个下标即可;

实现代码:

#include<bits/stdc++.h>
using namespace std; int main()
{
int t,i,a[],b[],c[],flag[];
cin>>t;
for(i=;i<=t;i++)
flag[i] = ;
for(i=;i<t;i++){
cin>>a[i];
flag[a[i]]++;
}
for(i=;i<t;i++)
cin>>b[i];
int cnt = ;
for(i=;i<t;i++){
if(a[i]!=b[i]){
c[cnt] = i;
cnt++;
}
}
if(cnt==){
for(i=;i<=t;i++){
if(flag[i]==){
a[c[]] = i;
}
}
}
else{if(flag[a[c[]]]>&&a[c[]]!=a[c[]])
a[c[]] = b[c[]];
else if(flag[a[c[]]]>&&a[c[]]==a[c[]]){
if(flag[b[c[]]]==)
a[c[]] = b[c[]];
else
a[c[]] = b[c[]];
}
else
a[c[]] = b[c[]];
}
for(i=;i<t-;i++)
cout<<a[i]<<" ";
cout<<a[t-]<<endl;
return ;
}

Codeforces Round #418 (Div. 2) B. An express train to reveries的更多相关文章

  1. Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque

    Codeforces Round #418 (Div. 2) D. An overnight dance in discotheque 题意: 给\(n(n <= 1000)\)个圆,圆与圆之间 ...

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

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

  3. Codeforces Round #418 (Div. 2).C two points

    C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...

  4. Codeforces Round #418 (Div. 2)

    A: 不细心WA了好多次 题意:给你一个a序列,再给你个b序列,你需要用b序列中的数字去替换a序列中的0,如果能够替换,则需要判断a是否能构成一个非递增的序列,a,b中所有的数字不会重复 思路:就是一 ...

  5. Codeforces Round #418 (Div. 2)D

    给n个圆要么包含,要么相分离,没有两个公共点,当成一棵树,把包含的面积大的放在上面 如图最上面的par记为-1,level记为0,当par==-1||level==1时就加否则减, 就是第一,二层先加 ...

  6. Codeforces Round #418 (Div. 2) C

    Description Nadeko's birthday is approaching! As she decorated the room for the party, a long garlan ...

  7. Codeforces Round #418 (Div. 2) B

    Description Sengoku still remembers the mysterious "colourful meteoroids" she discovered w ...

  8. Codeforces Round #418 (Div. 2) A

    Description A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight ...

  9. Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection

    C. An impassioned circulation of affection time limit per test 2 seconds memory limit per test 256 m ...

随机推荐

  1. 17-(基础入门篇)GPRS(Air202)串口

    https://www.cnblogs.com/yangfengwu/p/9968716.html 现在看一下官方给的demo 其实只要有两个就好说了 module(...,package.seeal ...

  2. php操作mysql使用的socket

    在本地安装了php,安装了mysql,mysql-server.mysql服务也启动了. php扩展中也有mysql > php -m | grep mysql 然而执行mysql_connec ...

  3. odoo学习之弹框显示

    按条件隐藏: <xpath expr="//group[1]" position="attributes"> <attribute name= ...

  4. Ionic buid android下的此工程不是一个android项目问题

    今天编译Ionic项目的时候报如下错误,甚是费解,之前一直都是好的 首先去检查了,相关JavaHome的环境变量,确定是好的,java -version 命令没有问题. 经查阅网上的解决方法,思路大都 ...

  5. macaca使用中问题解决方法整理

    报告老板:很多同学在搭建macaca的环境时候,出现了各种问题,尤其是使用windows的同学,更是复杂且费劲的要命,我这里针对一些遇到的坑,按照从头的搭建开始说起,如下 基本的搭建条件要满足基础环境 ...

  6. 牛客网-小白月赛6-J-洋灰三角

    题目链接https://www.nowcoder.com/acm/contest/136/J 这题我还是不找规律了,老老实实推吧,传说找规律也可以,我还是算了 递推式:f(n)=k*f(n-1)+p ...

  7. 阅读<构建之法>13、14、15、16、17章

    13章 这么多测试为什么不能整理出一个包括所有功能的测试呢?看着那么多测试都感觉奇怪了. 14章 怎样才能体现一个测试人员的工作价值呢?这样的判断又是否会太独断了? 15章 在时间上,会不会因不同功能 ...

  8. JSP中properties文件的路径问题

    做练习的时候,写了个properties文件,放在src/servlet/目录下,访问文件问题花了点时间折腾,最终得到解决,记下. 环境:eclipse jee oxygen,tomcat 9.0. ...

  9. [2017BUAA软件工程]第0次个人作业

    第一部分: 结缘计算机 1. 你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? 有时候我也问自己这个问题,是因为认识的人中有人从事这个工作并且做得很好而产生了艳羡?是因为家长一次次催逼,想 ...

  10. PAT 1012 数字分类

    https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840 给定一系列正整数,请按要求对数字进行分类,并 ...