题目链接:

  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. vue 安装与起步

    vue安装: 1.官网下载vue,在script标签里引用(去下载) 2.使用CDN(建议下载到本地,不推荐这种方法): BootCDN:https://cdn.bootcss.com/vue/2.2 ...

  2. NAND flash坏区

    计算容量 厂家所说的4G指的是4 000 000 000字节,是按1000进制计算的,而电脑是按照1024进制计算的,所以标称为4G的NAND Flash理论容量是4 000 000 000 / 10 ...

  3. 基于DM642 RAW采集格式的视频驱动开发及应用

    摘 要:为解决C64X系列数字信号处理器(DSP)视频驱动不能应用于原始数据格式(RAW)采集格式的问题,设计了DM642和电耦合元件(CCD)高清传感器的数据传输接口,并分析.修改用于标准格式的视频 ...

  4. java中InputStream String

    Java 中获取输入流时,有时候须要将输入流转成String,以便获取当中的内容 ,以下总结一下 InputStream 转成String 的方式  方法1: public String conver ...

  5. 使用Javamelody验证struts-spring框架与springMVC框架下action的訪问效率

    在前文中我提到了关于为何要使用springMVC的问题,当中一点是使用springMVC比起原先的struts+spring框架在效率上是有优势的.为了验证这个问题,我做了两个Demo来验证究竟是不是 ...

  6. Serializable 序列化 The byte stream created is platform independent. So, the object serialized on one platform can be deserialized on a different platform.

    Java 序列化接口Serializable详解 - 火星猿类 - 博客园 http://www.cnblogs.com/tomtiantao/p/6866083.html 深入理解JAVA序列化 - ...

  7. monggodb 复制集 集群 搭建

    https://docs.mongodb.com/manual/tutorial/enable-authentication/ Overview Enabling access control on ...

  8. umask文件屏蔽字的使用【学习笔记】

    #include "apue.h" #include <fcntl.h> #define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP ...

  9. 数据结构之 图论---图的深度遍历( 输出dfs的先后遍历序列 )

    图的深度遍历 Time Limit: 1000MS Memory limit: 65536K 题目描述 请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出.遍历时,先遍历节点编 ...

  10. linq to xml There are multiple root elements.

    添加xml结点的时候 var temp2 = temp1.Element("staticContent"); if (temp2 != null) { string str = & ...