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 ...
随机推荐
- nyoj 96-n-1位数 (strlen, atoi, ceil)
96-n-1位数 内存限制:64MB 时间限制:3000ms 特判: No 通过数:30 提交数:47 难度:1 题目描述: 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2) ...
- django:runserver实现远程访问
如果是在另一台电脑上web访问要用 python manage.py ip:port (一般使用8000)的形式:监听所有ip用0.0.0.0如下: 1 2 3 python manage.py ru ...
- [ML机器学习 - Stanford University] - Week1 - 01 Introduction
What is Machine Learning? Two definitions of Machine Learning are offered. Arthur Samuel described i ...
- 2019-11-20:xss学习笔记
xxe漏洞防御使用开发语言提供的禁用外部实体的方法phplibxml_disable_entity_loader(true); 卢兰奇对象模型,bom由于现代浏览器实现了js交互性方面的相同方法和属性 ...
- 【POJ 2823】【Luogu P1886】Sliding Window 滑动窗口
POJ 2823 Luogu P1886 [解题思路] 这是一个单调队列算法的经典题目,几乎学习单调队列的人都接触过这题. 利用单调队列算法求出每一个固定区间内的最(大/小)值. 以下以最大值为例: ...
- 今天是python专场UDP socket 链接
type = SOCK_DGRAM UDP 协议的通信优势 允许一个服务器的同时和多个客户端通信 server import socket sk = socket.socket(type=socket ...
- linux 进程简介
进程相关知识简介 进程定义: 一个运行中的程序即一个process task struct: 内核存储进程信息的固定格式称为task struct,task struct记录了例如该进程内存下一跳位置 ...
- 最全 HTTP 安全响应头设置指南
销售“安全记分卡”的公司正在崛起,并已开始成为企业销售的一个因素.这些公司组合使用 HTTP 安全报头和 IP 信誉来进行评级.不过,在很大程度上,公司的得分取决于对外开放网站上设置的安全响应报头.本 ...
- scrapy下载中间件结合selenium抓取全国空气质量检测数据
1.所需知识补充 1.下载中间件常用函数 process_request(self, request, spider): 当每个request通过下载中间件是,该方法被调用 process_reque ...
- python的time、datetime和calendar
datetime模块主要是用来表示日期的,就是我们常说的年月日时分秒,calendar模块主要是用来表示年月日,是星期几之类的信息,time模块主要侧重点在时分秒,从功能简单来看,我们可以认为三者是一 ...