CodeForces 669D Little Artem and Dance

模拟。

每个奇数走的步长都是一样的,每个偶数走的步长也是一样的。

记$num1$表示奇数走的步数,$num2$表示偶数走的步数。每次操作更新一下$num1$,$num2$。最后输出。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-‘0‘; c=getchar();}
}

bool f;
int n,q,num1,num2;
int ans[1000010];

int M(int x)
{
    if(x>=0) return x%n;
    int y=-x; int p=y/n+1;
    return (x+n*p)%n;
}

int main()
{
    scanf("%d%d",&n,&q); f=1;
    for(int i=1;i<=q;i++)
    {
        int op; scanf("%d",&op);
        if(op==1)
        {
            int x; scanf("%d",&x);
            num1=M(num1+x), num2=M(num2+x);
            if(x%2!=0) f=f^1;
        }
        else
        {
            if(f==0) num2=M(num2+1), num1=M(num1-1);
            else num1=M(num1+1), num2=M(num2-1);
            f=f^1;
        }
    }

    for(int i=1;i<=n;i++)
    {
        int pos;
        if(i%2==0) pos=(i+num2)%n;
        else pos=(i+num1)%n; if(pos==0) pos=n;
        ans[pos]=i;
    }
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
    printf("\n");
    return 0;
}
时间: 2024-08-08 01:08:24

CodeForces 669D Little Artem and Dance的相关文章

Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互换. 问:q次操作后,输出改变后的序列? 解题思路: 刚开始只看了第一组样例,发现相邻的奇偶位一直在一起,于是乎就开始writing code,写完后发现并不是正解!!!!就去推了一下第三个样例,总是这组实例通过,那组实例卡死,,,,,,,最后终于成功的Mengbility.今天突然想起来,其实整体

codeforces 442C C. Artem and Array(有深度的模拟)

题目 感谢JLGG的指导! 思路: //把数据转换成一条折线,发现有凸有凹 //有凹点,去掉并加上两边的最小值//无凹点,直接加上前(n-2)个的和(升序)//数据太大,要64位//判断凹与否,若一边等于,一边大于,那中间这个也算是凹进去的,所以判断时要加上等于 //有凹点,去掉并加上两边的最小值 //无凹点,直接加上前(n-2)个的和(升序) //数据太大,要64位 //判断凹与否,若一边等于,一边大于,那中间这个也算是凹进去的,所以判断时要加上等于 #include<stdio.h> #i

codeforces 641 C Little Artem and Dance

分析:算1和2的起点在哪里,然后往后累加就可以了. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; int ans[1000005]; int main() { //freopen("1.in",&q

CodeForces - 669D

题目链接:http://codeforces.com/problemset/problem/669/D 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

CodeForces 669C Little Artem and Matrix GNU

模拟. 把操作记录一下,倒着复原回去. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<

Codeforces Round #348

A. Little Artem and Presents 题意:Artem想将自己的n个糖果送给Masha,他想送尽量多的次数而不在乎数量,不顾每次送的数量不能和上次相同. 题解:只要第一次送一个,第二次送两个这样一次送就可以保证送的次数最多, 代码: 1 /*A*/ 2 #include<cstdio> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(scanf("%d",&n)!=EOF) 9

Codeforces Round #348(VK Cup 2016 - Round 2)

A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int n; scanf ("%d", &n); int ans = n / 3 * 2; if (n % 3) { ans++; } printf ("%d\n", ans);

Codeforces 442C Artem and Array(stack+贪心)

题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数,删除一个数的得分为两边数的最小值,如果左右有一边不存在则算作0分.问最大得分是多少. 解题思路:首先将连续的a,b,c,a > b && c > b的情况将c掉,获得min(a,b)分,这样处理后数组变成一个递増再递减的序列,除了最大和第二大的取不到,其他数字均可以得分. 样例:4 10 2 2 8 #include <cstdio> #include

codeforces 669E E. Little Artem and Time Machine(节点为map型的线段树)

题目链接: E. Little Artem and Time Machine time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of cours