CF1006A.Adjacent Replacements
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Mishka got an integer array a of length n 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 1 in the array a with 2;
- Replace each occurrence of 2 in the array a with 1;
- Replace each occurrence of 3 in the array a with 4;
- Replace each occurrence of 4 in the array a with 3;
- Replace each occurrence of 5 in the array a with 6;
- Replace each occurrence of 6 in the array a with 5;
- …
- Replace each occurrence of 109−1 in the array a with 109;
- Replace each occurrence of 109 in the array a with 109−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,2i) for each i∈1,2,…,5⋅108 as described above.
For example, for the array a=[1,2,4,5,10], the following sequence of arrays represents the algorithm:
[1,2,4,5,10] → (replace all occurrences of 1 with 2) → [2,2,4,5,10] → (replace all occurrences of 2 with 1) → [1,1,4,5,10] → (replace all occurrences of 3 with 4) → [1,1,4,5,10] → (replace all occurrences of 4 with 3) → [1,1,3,5,10] → (replace all occurrences of 5 with 6) → [1,1,3,6,10] → (replace all occurrences of 6 with 5) → [1,1,3,5,10] → … → [1,1,3,5,10] → (replace all occurrences of 10 with 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.
米什卡收到了一个长度为 n 的整数数组 a 作为生日礼物(真是个惊喜!)
米什卡不喜欢这份礼物,想对它做些改动。他发明了一种算法,并将其命名为“米什卡的相邻替换算法”。该算法可表示为一系列步骤:
- 将数组 a 中每个出现的 1 替换为 2;
- 将数组 a 中每个出现的 2 替换为 1;
- 将数组 a 中每个出现的 3 替换为 4;
- 将数组 a 中每个出现的 4 替换为 3;
- 将数组 a 中每个出现的 5 替换为 6;
- 将数组 a 中每个出现的 6 替换为 5;
- …
- 将数组 a 中每个出现的 109−1 替换为 109;
- 将数组 a 中每个出现的 109 替换为 109−1。
注意:该算法中间的省略号表示米什卡对每一对相邻整数 (2i−1,2i)(其中 i∈{1,2,…,5⋅108})均按上述方式执行这些替换操作。
例如,对于数组 a=[1,2,4,5,10],以下数组序列代表了该算法的执行过程:
[1,2,4,5,10] →(将所有 1 替换为 2)→ [2,2,4,5,10] →(将所有 2 替换为 1)→ [1,1,4,5,10] →(将所有 3 替换为 4)→ [1,1,4,5,10] →(将所有 4 替换为 3)→ [1,1,3,5,10] →(将所有 5 替换为 6)→ [1,1,3,6,10] →(将所有 6 替换为 5)→ [1,1,3,5,10] → … → [1,1,3,5,10] →(将所有 10 替换为 9)→ [1,1,3,5,9]。算法后续的步骤不再改变该数组。
米什卡非常懒,不愿亲自执行这些变换。但他对最终结果极为感兴趣。请帮助他找出该结果。
输入格式
The first line of the input contains one integer number n (1≤n≤1000) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.
输入的第一行包含一个整数 n(1≤n≤1000)—— 表示 Mishka 生日礼物中元素的个数(出人意料地,这是一个数组)。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 表示该数组的元素。
输出格式
Print n integers — b1,b2,…,bn, where bi is the final value of the i-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array a. Note that you cannot change the order of elements in the array.
输出 n 个整数 — b1,b2,…,bn,其中 bi 表示对数组 a 应用“Mishka 的相邻替换算法”后,数组中第 i 个元素的最终值。注意:你不能改变数组中元素的顺序。
输入输出样例
输入#1
5 1 2 4 5 10
输出#1
1 1 3 5 9
输入#2
10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
输出#2
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
说明/提示
The first example is described in the problem statement.
第一个示例在题目描述中已给出。
输入解题思路,AI测评打分。不知道怎么写?