Codeforces Round #395 (Div. 2)

题目链接:http://codeforces.com/contest/764/problem/B

题意:给定一个长度为n的最终序列,这个最终序列是通过若干次操作之后转换过来的。 操作的规则是:从i=1的位置开始每次翻转序列的[i,n-i+1]这部分位置,直到i

<=n-i+1位置,问你最开始的序列是怎么样的。

思路:手动模拟一下会发现,第一个位置和最后一个位置只交换过一次。第二个和倒数第二的位置交换了两次。 ... 总结就是奇数的位置(i)和对应的位置(n-i+1)交换了 奇数次,偶数的位置(i)和对应的位置(n-i+1)交换了偶数次。  交换了偶数次相当于没有交换,而交换了奇数次相当于只交换了一次。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<time.h>
#include<cmath>
using namespace std;
#define x first
#define y second
#define pb push_back
#define mp make_pair
typedef long long int LL;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int MAXN = 2e5 + 10;
int v[MAXN];
int main(){
//#ifdef kirito
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//#endif
//    int start = clock();
    int n;
    while (~scanf("%d", &n)){
        for (int i = 1; i <= n; i++){
            scanf("%d", &v[i]);
        }
        for (int i = 1; i <= n / 2; i++){
            if (i % 2){
                swap(v[i], v[n - i + 1]);
            }
        }
        for (int i = 1; i <= n; i++){
            printf("%d", v[i]);
            printf("%c", i == n ? '
' : ' ');
        }
    }
//#ifdef LOCAL_TIME
//    cout << "[Finished in " << clock() - start << " ms]" << endl;
//#endif
    return 0;
}
原文地址:https://www.cnblogs.com/kirito520/p/6363504.html