CodeForces - 669D Little Artem and Dance 想法题 多余操作

http://codeforces.com/problemset/problem/669/D

题意:n个数1~N围成一个圈。q个操作包括操作1:输入x, 所有数右移x。操作2:1,2位置上的数(swap(a[1], a[2])交换;3,4交换。。。。

题解:观察,发现所有奇数行为都是一样的,偶数同理,(对于操作1 两者相同,对于操作2 奇数位++,偶数位上--;

模拟1,2,即可,然后依次输出其它数字即可。(看清

ac代码:

#define    _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int maxn = 1e6  + 5;
const int mod= 1e9 + 5;
int a[maxn], x[maxn];
int main(){
    int n, q;
    cin >> n >> q;
    int A=1, B=2;
    for (int i = 1; i <= q; i++) {
        int x;
        scanf("%d", &x);
        
        if(x==1){
            scanf("%d", &x);
            A += x;
            B += x;
        }
        else {
            if (A & 1)A++, B--;
            else A--, B++;
        }
        A %= n;
        B %= n;
    }
    while (A <= 0)A += n;
    while (B <= 0)B += n;
    for (int i = 1; i < n; i+=2) {
        a[A] = i; a[B] = i + 1;
        A+=2; B+=2;
        if (A > n)A -= n;
        if (B > n)B -= n;
    }
    for (int i = 1; i <= n; i++)cout << a[i] << ' ';
}

 

转载于:https://www.cnblogs.com/SuuT/p/8543196.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值