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","r", stdin);
    //freopen("1.txt","w",stdout);
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        int x, y;
        int sum1=1, sum2=2;
        for(int i=1; i<=m; i++)
        {
            scanf("%d", &x);
            if(x==1)
            {
                scanf("%d", &y);
                sum1+=y;
                sum2+=y;
                sum1%=n;sum1+=n;sum1%=n;
                sum2%=n;sum2+=n;sum2%=n;
            }
            else
            {
                if(sum2%2)
                {
                    sum1--;
                    sum2++;
                }
                else
                {
                    sum1++;
                    sum2--;
                }
                sum1%=n;sum1+=n;sum1%=n;
                sum2%=n;sum2+=n;sum2%=n;
            }
        }
        sum1%=n;sum1+=n;sum1%=n;
        sum2%=n;sum2+=n;sum2%=n;
        for(int i=1; i<=n; )
        {
            if(sum1==0)
                sum1 = n;
            if(sum2==0)
                sum2 = n;
            ans[sum1] = i++;
            ans[sum2] = i++;
            sum1=(sum1+2+n)%n;
            sum2=(sum2+2+n)%n;
        }
        for(int i=1; i<=n; i++)
            printf("%d%c", ans[i],i==n?‘\n‘:‘ ‘);
    }

    return 0;
}
时间: 2024-08-24 23:34:14

codeforces 641 C 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 669D Little Artem and Dance

模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #i

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

@codeforces - [email&#160;protected] Little Artem and 2-SAT

目录 @[email protected] @[email protected] @accepted [email protected] @[email protected] @[email protected] 给定两个 2-sat 问题,询问两个问题的解集是否相同. 如果不相同,构造一组解 {xi},使得这个解是其中一个问题的解同时不是另一个问题的解. 原题链接. @[email protected] 如果两者解集都为空,那么解集相同. 如果两者只有一个解集为空,则取另一个问题的任意解即可.

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 C. Artem and Array(有深度的模拟)

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

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 442C Artem and Array(贪心)

E - Artem and Array Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2014-08-21) Description Artem has an array of n positive integers. Artem decided to play with it. T