codeforces 814B An express train to reveries(思维)

来源:互联网 发布:python splinter 安装 编辑:程序博客网 时间:2024/05/14 12:10

 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
51 2 3 4 31 2 5 4 5
output
1 2 5 4 3
input
54 4 2 3 15 4 5 3 1
output
5 4 2 3 1
input
41 1 3 41 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.


给两个数组(元素为1-n)a, b求一个数组c 使a,与b中的元素与c 恰好只有一个元素不同,思维的精简度,直接求出a中重复的那个元素,用没出现的元素代替

判断是否满足条件即可,不可能出现没有重复的情况因为这样会导致要改的元素不止一个;。。。写题目前一定要把问题想清楚,不要急着下手



#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<cmath>#include <bits/stdc++.h>using namespace std;const int N = 3e5+10;typedef long long LL;int a[N], b[N],p1[N], p2[N], v1[N], v2[N];int l1=0,l2=0;int main(){    int n;    scanf("%d", &n);    memset(v1,0,sizeof(v1));    memset(v2,0,sizeof(v2));    for(int i=1; i<=n; i++)    {        scanf("%d", &a[i]);        v1[a[i]]++;    }    int k1=0, k2=0;    for(int i=1; i<=n; i++)    {        if(v1[i]==0) l1=i;        if(v1[i]>1) l2=i;    }    for(int i=1;i<=n;i++)    {        if(v1[a[i]]>1) p1[k1++]=i;    }    for(int i=1; i<=n; i++)   scanf("%d", &b[i]);    int h1=p1[0], h2=p1[1], cnt=0;    a[h1]=l1;    for(int i=1;i<=n;i++)    {        if(a[i]!=b[i]) cnt++;    }    if(cnt==1)    {        for(int i=1; i<=n; i++) printf("%d%c",a[i],i==n?'\n':' ');        return 0;    }    a[h1]=a[h2];    a[h2]=l1;    for(int i=1; i<=n; i++) printf("%d%c",a[i],i==n?'\n':' ');    return 0;}









原创粉丝点击