Atcoder ARC 077 C - pushpush 模拟

题意:

个数,有两种操作,每次把这个数加到序列末端,然后翻转序列。

样例解释:

Sample Input 1
4
1 2 3 4
Sample Output 1
4 2 1 3

  • After step 1 of the first operation, b becomes: 1.
  • After step 2 of the first operation, b becomes: 1.
  • After step 1 of the second operation, b becomes: 1,2.
  • After step 2 of the second operation, b becomes: 2,1.
  • After step 1 of the third operation, b becomes: 2,1,3.
  • After step 2 of the third operation, b becomes: 3,1,2.
  • After step 1 of the fourth operation, b becomes: 3,1,2,4.
  • After step 2 of the fourth operation, b becomes: 4,2,1,3.
  • Thus, the answer is 4 2 1 3.
算法:

倒着模拟一遍…

代码:
#include <bits/stdc++.h>

/*
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read() {
    t x = 0; int f = 1; char c = getchar();
    while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
    return x * f;
}

template<typename t> void write(t x) {
    if (x < 0){
        putchar('-'), write(-x);
        return;
    }
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int N = 3e5 + 10;
int a[N], b[N], n;

int main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    n = rdi();
    for (int i = 1; i <= n; i ++) a[i] = rdi();
    int l = 1, r = n, k = 0;
    for (int i = n; i; i --) {
        if (!k) b[l++] = a[i];
        else b[r --] = a[i];
        k ^= 1;
    }
    for (int i = 1; i <= n; i ++) write(b[i]), putchar(32);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值