题目链接:

  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. 理解OpenStack认证:Keystone PKI

    原文链接: https://www.mirantis.com/blog/understanding-openstack-authentication-keystone-pki/ The latest ...

  2. zTree async 动态参数处理

    async:{ enable: true,//开启异步机制 url: opts.url,//异步地址 otherParam: {  'plateNo': function(){ return $('# ...

  3. swing_tableModel 创建表格

    import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.Panel; import java.util.Ar ...

  4. Hihocoder #1014 : Trie树 (字典数树统计前缀的出现次数 *【模板】 基于指针结构体实现 )

    #1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...

  5. ES6 解构赋值的常见用途,很强大

    字符串 var [a,b,c,d,e] = "hello"; console.log(a); // h console.log(b); // e console.log(c); / ...

  6. html5--6-13 CSS3中的颜色表示方式

    html5--6-13 CSS3中的颜色表示方式 学习要点 掌握选择器的优先级问题 掌握CSS3中新增的颜色表示方式 选择器的优先级问题 原则上:元素选择器<类选择器< ID选择器< ...

  7. html5--6-2 CSS语法

    html5--6-2 CSS语法 实例 学习要点 掌握引入外部样式表方法 插入样式的三种方法 内联样式表(行内) 内部样式表(style中) 外部样式表 创建一个外部样式表 在head中使用link元 ...

  8. dba操作之archivelog清理

    下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的: crosscheck archivelog all;                        ...

  9. skynet源码阅读<2>--网络部分

    先来看下socket_server的数据结构,这里简称为ss: struct socket_server { int recvctrl_fd; int sendctrl_fd; int checkct ...

  10. [Java] 继承,隐藏,覆盖,重载,多态,抽象类,接口

    1.子类 class SonClass extends ABC{...} 在子类定义后,子类中就可以直接隐式包含父类的成员变量和方法,而不用再写,这就是使用继承的优点. 子类包含父类的成员,不是子类和 ...