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 ...
随机推荐
- SAP HCM 评估路径
一.评估路径的配置方法: 1)IMG菜单路径:人事管理-〉组织管理-〉基本设置-〉维护评估路径: 2)首先定义评估路径的名称和描述,客户自定义的评估路径的名称编码可以采用字母数字编码,最大长度是八 ...
- 微软的分布式应用框架 Dapr
微服务架构已成为构建云原生应用程序的标准,微服务架构提供了令人信服的好处,包括可伸缩性,松散的服务耦合和独立部署,但是这种方法的成本很高,需要了解和熟练掌握分布式系统.为了使用所有开发人员能够使用任何 ...
- getClass()和instanceof以及类的equals方法
在比较两个类时,常见有两种做法,一种是x.getClass() == y; 一种是x instanceof y,下面我们来比较这两种做法的区别. getClass()返回一个对象所属的类 public ...
- java多线程回顾1:线程的概念与创建
1.进程与线程的概念 现在几乎所有操作系统都支持多任务,通常一个任务就是一个程序,一个运行中的程序就是一个进程.当一个程序行时,其内部也可能在执行多个任务,进程内每一个任务的执行流,就是一个线程. 所 ...
- 微擎使用post提交,并显示弹出层
微擎使用post提交,并显示弹出层 function changeStatus(id, status) { // 提交数据 var id = parseInt(id); var status = pa ...
- MySQL如何永久解决由dos编码格式导致MySQ的显示乱码
MySQL如何永久解决由dos编码格式导致MySQ的显示乱码 Ⅰ.新建文件 changeCode.txt Ⅱ.粘贴下面代码(作用:将默认的GBK(936)修改为UTF-8(65001)) Window ...
- 附009.Kubernetes永久存储之GlusterFS独立部署
一 前期准备 1.1 基础知识 Heketi提供了一个RESTful管理界面,可以用来管理GlusterFS卷的生命周期.Heketi会动态在集群内选择bricks构建所需的volumes,从而确保数 ...
- 领扣(LeetCode)字符串相加 个人题解
给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 注意: num1 和num2 的长度都小于 5100. num1 和num2 都只包含数字 0-9. num1 和num2 都不包 ...
- Redux第一节
安装脚手架 npm i -g create-react-app 创建一个Dom create-react-app demo01 安装 Ant Design npm i antd --save 安装re ...
- BIM到底是啥?
近年来随着BIM的大火以及一些政策的支持,BIM逐渐走入建筑行业的视野,但其实大部分人都不知道或者说不了解BIM到底是啥.去百度上进行搜索,你会知道BIM就是Building Infor ...