CodeForces1006A - Adjacent Replacements
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.
题解:水题。。其实只要把偶数减一,奇数不变即可;
AC代码为:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,num[1010];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>num[i];
if((num[i]&1) ==0) num[i]-=1;
}
for(int i=0;i<n;i++) cout<<num[i]<<" ";
cout<<endl;
return 0;
}
CodeForces1006A - Adjacent Replacements的更多相关文章
- CodeForces Round #498 Div.3 A. Adjacent Replacements
http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthd ...
- Codeforces Div3 #498 A-F
. A. Adjacent Replacement ...
- Codeforces Round #498 (Div. 3) 简要题解
[比赛链接] https://codeforces.com/contest/1006 [题解] Problem A. Adjacent Replacements [算法] 将序列中的所有 ...
- 【CSS3】Advanced3:Universal, Child, and Adjacent Selectors
1.Universal selectors eg:#target*{ } 2.Child selectors < something immediately nested within some ...
- [CC-ADJLEAF2]Adjacent Leaves
[CC-ADJLEAF2]Adjacent Leaves 题目大意: 给定一棵有根树,考虑从根开始进行DFS,将所有叶子按照被遍历到的顺序排列得到一个序列. 定义一个叶子集合合法,当且仅当存在一种DF ...
- Adjacent Bit Counts(01组合数)
Adjacent Bit Counts 4557 Adjacent Bit CountsFor a string of n bits x 1 , x 2 , x 3 ,..., x n , the a ...
- 微软BI 之SSRS 系列 - 使用 LookupSet 和 Adjacent Group 等高级技巧在报表中跨 Dataset 分组查询
SSRS 报表中有一些高级的技巧,平常很少用到,下面我通过这个案例来展现一下如何在实际开发中使用它们,并且如何解决一些实际的需求. 这张报表分别统计了不同的 Product 产品在不同的月份的 Ord ...
- nyoj 715 Adjacent Bit Counts
描述 For a string of n bits x1, x2, x3, …, xn, the adjacent bit count of the string is given by ...
- Adjacent Bit Counts(uvalive)
For a string of n bits x1, x2, x3,…, xn, the adjacent bit count of the string (AdjBC(x)) is given by ...
随机推荐
- [LC]235题 二叉搜索树的最近公共祖先 (树)(递归)
①题目 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 x 是 p.q 的祖先 ...
- nuxt遇到的问题(一)window 或 document is not defined
因为用了VUE做的官网,既然是官网了避免不了SEO的问题了(该死当初就不应该选择用vue) 很自然就是选择了使用nuxt.js来做ssr预渲染了. 因为网站不是响应式的,PC / 移动端要进行对应跳转 ...
- nyoj 53-不高兴的小明 (遍历)
53-不高兴的小明 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:28 submit:89 题目描述: 小明又出问题了.妈妈认为聪明的小明应该 ...
- C语言|博客作业09
这个作业属于哪个课程 C语言程序设计II 这个作业的要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-1/homework/10027 我在这个课程 ...
- Java描述设计模式(21):状态模式
本文源码:GitHub·点这里 || GitEE·点这里 一.生活场景 1.场景描述 变色龙是爬行动物,是非常奇特的动物,它有适于树栖生活的种种特征和行为,身体也会随着环境的变化而变化出适应环境的颜色 ...
- shell脚本1——变量 $、read、``
与Shell变量相关的几个命令: 变量只在当前Shell中生效. source 这个命令让脚本影响他们父Shell的环境(. 可以代替source命令) export 这个命令可以让脚本影响其子She ...
- SpringBoot让你的Bean动起来(自定义参数解析HandlerMethodArgumentResolver)
SpringBoot让你的Bean动起来(自定义参数解析HandlerMethodArgumentResolver) 简介 我们 Controller 用到的一些 Bean 需要通过一定的方式去获取的 ...
- vue3.0里的生命周期函数
- go语言学习笔记(二)
整数 有符号整数 int8 int16 int32 int64 无符号整数 uin8 uin16 uin32 uin64 无符号整数 uintptr可以进行运算这点很重要请了解unsafe包,大小不明 ...
- FPGA基础(verilog语言)——语法篇(续1)
上一篇文章提到了FPGA中一个模块基本结构,这篇文章开始介绍语法. 首先,我们学习一门语言都要从这门语言的单词学起,所以verilog中的关键词都有哪些呢?看下面: A:always.assign B ...