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. js 检测浏览器

    首先还是IE浏览器的检测,一般我们在写代码的时候,出现的兼容性bug几乎都来自IE.从IE10以后,IE还算有点良心,支持了大部门的CSS3及H5的新特性.那么在IE10之前呢,就要才去别的手段来代替 ...

  2. npm 常用命令详解

    本文以Windows平台上做测试,以gulp为示例做教程,出自作者白树,转载请声明出处! 目录 npm是什么 npm install 安装模块 npm uninstall 卸载模块 npm updat ...

  3. 基于webpack2.x的vue2.x的多页面站点

    vue的多页面 依旧使用vue-cli来初始化我们的项目 然后修改主要目录结构如下: ├── build │   ├── build.js │   ├── check-versions.js │   ...

  4. WEB服务器如何选择 Apache or Nginx?

    Web服务器是直接影响网站性能的关键因素,也是每个站长选择网站运营环境时必然考虑的问题.目前Web服务器市场产品众多,最为主流和代表性的当属Apache.Nginx以及微软的IIS.本文目的是通过Ap ...

  5. Linux下链接数据库图形化工具

    (一).Linux环境下mysql的安装.SQL操作 Linux下安装MySQL (rmp --help) 基本步骤:上传软件->检查当前Linux环境是否已经安装,如发现系统自带的,先卸载-& ...

  6. vue2.0实践 —— Node + vue 实现移动官网

    简介 使用 Node + vue 对公司的官网进行了一个简单的移动端的实现. 源码 https://github.com/wx1993/node-vue-fabaocn 效果 组件 轮播图(使用 vu ...

  7. MACD指标

    MACD(Moving Average Convergence)平滑异同移动平均线 MACD指标有双移动平均线发展而来,由快速移动平均线减去慢速移动平均线,当MACD从负数转向证书,是买入信号,从正数 ...

  8. 利用gulp搭建简单服务器,gulp标准版

    var gulp = require('gulp'), autoprefixer = require('gulp-autoprefixer'), //自动添加css前缀 rename = requir ...

  9. python小工具:用python操作HP的Quality Center

    背景是这样的:这个组的测试人员每跑一个case都要上传测试结果附件到QC.每个待测功能模块可能包含几十上百的case.于是手工上传测试结果变成了繁重的体力劳动.令人惊讶的是我们的工具开发组竟然说做不了 ...

  10. git常用命令记录

    配置本地仓库 git config --global user.name.git config --global user.email 查看配置详情 git config -l 初始仓库 git in ...