题目链接:

  Codeforces 669D Little Artem and Dance

题目描述:

  给一个从1到n的连续序列,有两种操作:

    1:序列整体向后移动x个位置,

    2:序列中相邻的奇偶位置互换。

  问:q次操作后,输出改变后的序列?

解题思路:

  刚开始只看了第一组样例,发现相邻的奇偶位一直在一起,于是乎就开始writing code,写完后发现并不是正解!!!!就去推了一下第三个样例,总是这组实例通过,那组实例卡死,,,,,,,最后终于成功的Mengbility。今天突然想起来,其实整体向后移动,奇偶位置交换,并不会影响奇数的顺序和偶数的顺序。所以只需要记录1的位置和2的位置即可。

 #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std; const int maxn = ;
int ans[maxn]; int main ()
{
int n, q; while (scanf ("%d %d", &n, &q) != EOF)
{
int wz1 = , wz2 = ; while (q --)
{
int op, x; scanf ("%d", &op); if (op == )
{
scanf ("%d", &x);
wz1 = ((wz1 + x) % n + n) % n;
wz2 = ((wz2 + x) % n + n) % n;
}
else
{
int a = wz1 % ? - : ;
int b = wz2 % ? - : ; wz1 = ((wz1 + a) % n + n) % n;
wz2 = ((wz2 + b) % n + n) % n;
}
} for (int i=; i<n; i+=)
{
ans[(i+wz1)%n] = i + ;
ans[(i+wz2)%n] = i + ;
}
for (int i=; i<n; i++)
printf ("%d%c", ans[i], i==n-?'\n':' ');
}
return ;
}

Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)的更多相关文章

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

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  2. CodeForces 669D Little Artem and Dance

    模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...

  3. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  4. CodeForces 668B Little Artem and Dance

    B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...

  5. Codeforces 394D Physical Education and Buns 胡搞

    题目链接:点击打开链接 题意:给定n个数的序列(能够排序) 操作一次能够使得某个数++或--. 问最少操作几次使得序列变成一个等差序列 输出: 第一行输出最少操作的次数 第二行输出等差数列里的最小项 ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  7. D. Little Artem and Dance

    题目链接:http://codeforces.com/problemset/problem/669/D D. Little Artem and Dance time limit per test 2 ...

  8. [LeetCode]Integer Break(Dp或胡搞或推公式)

    343. Integer Break Given a positive integer n, break it into the sum of at least two positive intege ...

  9. HDU 4690 EBCDIC (2013多校 1005题 胡搞题)

    EBCDIC Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total Su ...

随机推荐

  1. openwrt gstreamer实例学习笔记(五. gstreamer BUS)

    1)概述 BUS(总线) 是一个简单的系统,它采用自己的线程机制将一个管道线程的消息分发到一个应用程序当中.总线的优势是:当使用GStreamer的时候,应用程序不需要线程识别,即便GStreamer ...

  2. 【读后感】Netty 系列之 Netty 高性能之道 - 相比 Mina 怎样 ?

    [读后感]Netty 系列之 Netty 高性能之道 - 相比 Mina 怎样 ? 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...

  3. 编程算法 - 数组中出现次数超过一半的数字 代码(C)

    数组中出现次数超过一半的数字 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 数组中有一个数字出现的次数超过数组长度的一半, 请找出这个数字. ...

  4. 利用easyUI的combobox打造自己主动提示组件

    自己主动提示是时下一个非常流行的功能,比方说百度.谷歌的搜索输入框都使用到了这么一个功能. 因为easyUI的combobox设计师已经考虑到了这个功能.所以仅仅需简单几步我们能够轻松打造自己的自己主 ...

  5. Html.Partial

    老革命永远都在遇上各种似是而非的老问题. 这次,是这个Html.Partial,分部页. Html.Partial与Html.Action有啥区别呢?区别就是,Html.Partial只有一个视图,而 ...

  6. Cluster Mode Overview

    https://spark.apache.org/docs/latest/cluster-overview.html

  7. PrintWrite

    向文本输出流打印对象的格式化表示形式.此类实现在 PrintStream 中的所有 print 方法.它不包含用于写入原始字节的方法,对于这些字节,程序应该使用未编码的字节流进行写入. 与 Print ...

  8. Android源代码下载过程中无法下载repo的解决方法【转】

    本文转载自:http://blog.csdn.net/shangyuan21/article/details/17618575 我们都知道下载Android源代码需要使用repo进行辅助下载,但是最进 ...

  9. [存档]获取通讯录信息并写到SD卡上

      下面是代码,不过没有字母表的顺序排列: package com.example.getcontacts; import java.io.FileWriter; import java.io.IOE ...

  10. 「LuoguP3369」 【模板】普通平衡树 (用vector乱搞平衡树

    Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入 x 数 删除 x 数(若有多个相同的数,应只删除一个) 查询 x 数的排名(排名定义为比当前 ...