• D. Little Artem and Dance


    题目链接:http://codeforces.com/problemset/problem/669/D

    D. Little Artem and Dance
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.

    More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:

    1. Value x and some direction are announced, and all boys move x positions in the corresponding direction.
    2. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.

    Your task is to determine the final position of each boy.

    Input

    The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.

    Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while  - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.

    Output

    Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.

    Examples
    Input
    Copy
    6 3
    1 2
    2
    1 2
    Output
    Copy
    4 3 6 5 2 1
    Input
    Copy
    2 3
    1 1
    2
    1 -2
    Output
    Copy
    1 2
    Input
    Copy
    4 2
    2
    1 3
    Output
    Copy
    1 4 3 2

    题目大意:输入n,代表有n对男女,1···n。所有人围成一个圈, 刚开始男1与女1,男2与女2···对应,q代表有q次操作,如果输入的是1,则所有男的移动x位,正代表顺时针,负代表逆时针。如果输入的是2,则男1与男2交换位子,男3与
    男4交换位子···
    个人思路:不论怎么操作,其实男1后面两位一定是3,后面4位一定是5·····男2后面两位一定是4,后面四位一定是6····,所以我们只要记录男1和男2的位子,就能知道所有人的位子了
    看代码(但这题要用scanf,不然会超时)
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<stdio.h>
    #include<string.h>
    #include<cmath>
    #include<math.h>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<map>
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const int maxn=1e6+10;
    const int maxk=100+10;
    const int maxx=1e4+10;
    const ll maxa=43200;
    #define INF 0x3f3f3f3f3f3f
    int a[maxn];
    int main()
    {
        int n,q,p1,p2,m,x;
        scanf("%d%d",&n,&q);
        p1=0;
        p2=1;
        for(int i=1;i<=q;i++)
        {
            scanf("%d",&m);
            if(m==1)
            {
                scanf("%d",&x);
                if(x<0)
                    x+=n;
                p1+=x;
                p2+=x;
                p1%=n;
                p2%=n;
            }
            else
            {
                if(p1%2==0)
                {
                    p1+=1;
                }
                else
                {
                    p1-=1;
                    //p1=(p1+n)%n;
                }
                if(p2%2==0)
                {
                    p2+=1;
                }
                else
                {
                    p2-=1;
                  //  p2=(p2+6)%6;
                }
            }
        }
        a[p1]=1;
        a[p2]=2;
        int t=n/2;
        int sum=2;
        while(--t)
        {
            sum+=2;
            a[(p2+2)%n]=sum;
            p2=(p2+2)%n;
        }
        t=n-n/2;
        sum=1;
        while(--t)
        {
            sum+=2;
            a[(p1+2)%n]=sum;
            p1=(p1+2)%n;
        }
        for(int i=0;i<n;i++)
            printf("%d ",a[i]);
        printf("
    ");
        return 0;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    VC++以及VS个版本比较 及 C++编译器比较
    这本书的封面
    json_encode(),json_deocde()用法说明
    循环匹配,一般用于多选列表选中状态
    js判断变量是否被定义
    js onload()事件调用方法
    js push使用方法
    iframe去掉边滚动条
    ajax上传文件(使用ajaxfileupload)
    基于url的权限控制
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9350227.html
Copyright © 2020-2023  润新知