ACM-FJNU18级第二次友谊赛E题-找规律+翻译题

ACM-FJNU18级第二次友谊赛E题

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 asequence 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} asdescribed 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.

INPUT
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.

OUPUT
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.
在这里插入图片描述

教练说:英文越长的题越简单。
emm实际上一开始做的时候第一眼看的是样例,发现偶数输入就减一,奇数输入不变,数据大的时候也是这样。
以防万一,翻译了一下题目,在描述具体操作的那一段中发现确实是这么回事qwq。
AC代码

#include <string.h>
#include <bits/stdc++.h>
#define N 10050
#define double pai = 4.0*atan(1.0)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long int ll;
ll ar[N];
ll br[N]; 
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%lld", &ar[i]);
		if(!(ar[i]&1)) ar[i]--;
	}
	for(int i = 0; i < n; i++){
		if(i == 0) printf("%lld", ar[i]);
		else printf(" %lld", ar[i]);
	}
	return 0;//学艺不精,告辞
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值