zoukankan      html  css  js  c++  java
  • 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 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 1091109−1 in the array aa with 109109;
    • Replace each occurrence of 109109 in the array aa with 1091109−1.

    Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2i1,2i2i−1,2i) for each i{1,2,,5108}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 (1n10001≤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 (1ai1091≤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

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    int num[1010];
    
    int main() {
        scanf("%d", &N);
        for(int i = 1; i <= N; i ++) {
            scanf("%d", &num[i]);
            if(num[i] % 2 == 0)
                num[i] -= 1;
        }
    
        for(int i = 1; i <= N; i ++) {
            printf("%d", num[i]);
            printf("%s", i != N ? " " : "
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    gradle使用笔记
    MaxScale初探
    mariadb-10GTID复制及多源复制
    Shell中的循环语句实例
    Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
    学习MongoDB--(5-2):索引(查看索引的使用,管理索引)
    MongoDB索引管理
    mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别
    MongoDB增加用户、删除用户、修改用户读写权限及只读权限(注:转载于http://www.2cto.com/database/201203/125025.html)
    MongoDB创建数据库
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9933843.html
Copyright © 2011-2022 走看看