2018暑期SICNU-ACM組集訓(xùn)報(bào)告(2)

題目:
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 1 in the array aa with 2;
Replace each occurrence of 2 in the array aa with 1;
Replace each occurrence of 3 in the array aa with 4;
Replace each occurrence of 4 in the array aa with 3;
Replace each occurrence of 5 in the array aa with 6;
Replace each occurrence of 6 in the array aa with 5;
……
Replace each occurrence of 10^9?1 in the array aa with 10^9;
Replace each occurrence of 10^9 in the array aa with 10^9?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 1 with 2) →→ [2,2,4,5,10][2,2,4,5,10] →→ (replace all occurrences of 2 with 1) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 3 with 4) →→ [1,1,4,5,10][1,1,4,5,10] →→ (replace all occurrences of 4 with 3) →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 5 with 6) →→ [1,1,3,6,10][1,1,3,6,10] →→ (replace all occurrences of 6 with 5) →→ [1,1,3,5,10][1,1,3,5,10] →→ …… →→ [1,1,3,5,10][1,1,3,5,10] →→ (replace all occurrences of 10 with 9) →→ [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
5
1 2 4 5 10
Output
1 1 3 5 9
Input
10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
Output
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
Note
The first example is described in the problem statement.

[原題鏈接]:http://codeforces.com/problemset/problem/1006/A

題意:把規(guī)定長(zhǎng)度數(shù)組中的值按照1→2、2→1定鸟、3→4译株、4→3的規(guī)律進(jìn)行交換缸匪,以此類(lèi)推到10^9 →10^9?1 .

解題思路:乍一看上去是有一點(diǎn)點(diǎn)想要暴力的意思,但是我覺(jué)得遍歷完可能就超時(shí)了蹦浦,所以我選擇看看規(guī)律篇裁。

不出所料的,在仔細(xì)觀(guān)察后肾砂,得到如下規(guī)律:數(shù)組中奇數(shù)不變,偶數(shù)減一宏悦。這下就是一道水題了镐确,不過(guò)關(guān)鍵還是思路包吝,不能只想著暴力破解

AC代碼:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[1000],n,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0){
            a[i]=a[i]-1;
        }
    }
    for(i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市源葫,隨后出現(xiàn)的幾起案子诗越,更是在濱河造成了極大的恐慌,老刑警劉巖息堂,帶你破解...
    沈念sama閱讀 217,185評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嚷狞,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡荣堰,警方通過(guò)查閱死者的電腦和手機(jī)床未,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,652評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)振坚,“玉大人薇搁,你說(shuō)我怎么就攤上這事÷挪Γ” “怎么了只酥?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,524評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵褥实,是天一觀(guān)的道長(zhǎng)呀狼。 經(jīng)常有香客問(wèn)我,道長(zhǎng)损离,這世上最難降的妖魔是什么哥艇? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,339評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮僻澎,結(jié)果婚禮上貌踏,老公的妹妹穿的比我還像新娘。我一直安慰自己窟勃,他們只是感情好祖乳,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,387評(píng)論 6 391
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著秉氧,像睡著了一般眷昆。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上汁咏,一...
    開(kāi)封第一講書(shū)人閱讀 51,287評(píng)論 1 301
  • 那天亚斋,我揣著相機(jī)與錄音,去河邊找鬼攘滩。 笑死帅刊,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的漂问。 我是一名探鬼主播赖瞒,決...
    沈念sama閱讀 40,130評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼女揭,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了栏饮?” 一聲冷哼從身側(cè)響起田绑,我...
    開(kāi)封第一講書(shū)人閱讀 38,985評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎抡爹,沒(méi)想到半個(gè)月后掩驱,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,420評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡冬竟,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,617評(píng)論 3 334
  • 正文 我和宋清朗相戀三年欧穴,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片泵殴。...
    茶點(diǎn)故事閱讀 39,779評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡涮帘,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出笑诅,到底是詐尸還是另有隱情调缨,我是刑警寧澤,帶...
    沈念sama閱讀 35,477評(píng)論 5 345
  • 正文 年R本政府宣布吆你,位于F島的核電站弦叶,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏妇多。R本人自食惡果不足惜伤哺,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,088評(píng)論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望者祖。 院中可真熱鬧立莉,春花似錦、人聲如沸七问。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,716評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)械巡。三九已至刹淌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間坟比,已是汗流浹背芦鳍。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,857評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留葛账,地道東北人柠衅。 一個(gè)月前我還...
    沈念sama閱讀 47,876評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像籍琳,于是被迫代替她去往敵國(guó)和親菲宴。 傳聞我的和親對(duì)象是個(gè)殘疾皇子贷祈,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,700評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,324評(píng)論 0 10
  • 慣性思維, 是親友在我們記憶中對(duì)應(yīng)的標(biāo)簽喝峦。 當(dāng)互動(dòng)中一旦發(fā)生交錯(cuò)式溝通势誊, 我們會(huì)不假思索, 馬上用這個(gè)標(biāo)簽去定義T...
    守望者22閱讀 155評(píng)論 4 1
  • 今天你又做了什么谣蠢?計(jì)劃粟耻?目標(biāo)?行動(dòng)眉踱? 一轉(zhuǎn)眼今天是2008年的一月八號(hào)了挤忙,早上十一點(diǎn)多了…… ...
    諄兒閱讀 141評(píng)論 0 0