欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

1006A Adjacent Replacements

程序员文章站 2022-04-03 08:20:25
...

A. Adjacent Replacements

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mishka got an integer array aa of length nn as a birthday present (what a surprise!).

Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:

  • Replace each occurrence of 11 in the array aa with 22;
  • Replace each occurrence of 22 in the array aa with 11;
  • Replace each occurrence of 33 in the array aa with 44;
  • Replace each occurrence of 44 in the array aa with 33;
  • Replace each occurrence of 55 in the array aa with 66;
  • Replace each occurrence of 66 in the array aa with 55;
  • ……
  • Replace each occurrence of 109−1109−1 in the array aa with 109109;
  • Replace each occurrence of 109109 in the array aa with 109−1109−1.

Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i−1,2i2i−1,2i) for each i∈{1,2,…,5⋅108}i∈{1,2,…,5⋅108}as described above.

For example, for the array a=[1,2,4,5,10]a=[1,2,4,5,10], the following sequence of arrays represents the algorithm:

[1,2,4,5,10][1,2,4,5,10] →→ (replace all occurrences of 11 with 22) →→ [2,2,4,5,10][2,2,4,5,10] →→ (replace all occurrences of 22 with 11) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 33 with 44) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 44 with 33) →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 55 with 66) →→ [1,1,3,6,10][1,1,3,6,10] →→ (replace all occurrences of 66 with 55) →→ [1,1,3,5,10][1,1,3,5,10] →→ …… →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 1010 with 99) →→ [1,1,3,5,9][1,1,3,5,9]. The later steps of the algorithm do not change the array.

Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.

Input

The first line of the input contains one integer number nn (1≤n≤10001≤n≤1000) — the number of elements in Mishka's birthday present (surprisingly, an array).

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

Print nn integers — b1,b2,…,bnb1,b2,…,bn, where bibi is the final value of the ii-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array aa. Note that you cannot change the order of elements in the array.

Examples

input

Copy

5
1 2 4 5 10

output

Copy

1 1 3 5 9

input

Copy

10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000

output

Copy

9999 9 50605065 1 5 89 5 999999999 60506055 999999999

Note

The first example is described in the problem statement.

 

题意:给你一串字符,2i和2i-1能够互相替换,i∈{1,2,…,5⋅...,10^8},例如对于数组a=[1,2,4,5,10]a=[1,2,4,5,10],以下数组序列表示该算法:

[1,2,4,5,10][1,2,4,5,10] →→(替换所有发生在11带着22) →→ [2,2,4,5,10][2,2,4,5,10] →→(替换所有发生在22带着11) →→ [1,1,4,5,10][1,1,4,5,10] →→(替换所有发生在33带着44) →→ [1,1,4,5,10][1,1,4,5,10] →→(替换所有发生在44带着33) →→ [1,1,3,5,10][1,1,3,5,10] →→(替换所有发生在55带着66) →→ [1,1,3,6,10][1,1,3,6,10] →→(替换所有发生在66带着55) →→ [1,1,3,5,10][1,1,3,5,10] →→ …… →→ [1,1,3,5,10][1,1,3,5,10] →→(替换所有发生在1010带着99) →→ [1,1,3,5,9][1,1,3,5,9]。算法的后续步骤不会更改数组。让我们输出经过这种算法,最后的每个元素。

题解:规律题  可以发现,奇数都不变,偶数减一,所以....

c++:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[2010];
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i],printf("%d ",a[i]%2?a[i]:a[i]-1);
    return 0;
}

python:

n=input()
a=list(map(int,input().split()))
ans=[i+i%2-1 for i in a]
for i in ans:
    print(i,end=' ')

 

相关标签: 规律