Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
2 seconds
256 megabytes
standard input
standard output
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 of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
- Value x and some direction are announced, and all boys move x positions in the corresponding direction.
- Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.
Your task is to determine the final position of each boy.
The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.
Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.
Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.
6 3
1 2
2
1 2
4 3 6 5 2 1
2 3
1 1
2
1 -2
1 2
4 2
2
1 3
1 4 3 2 题意:1~n编号的女孩与1~n编号的男孩配对围圈跳舞
两种操作
1 x 若x为正值 所有的男孩顺时针移动x个位置 继续与女孩跳舞 若为负值 则逆时针移动
2 奇偶位置男孩交换位置(这里的奇偶位置是 根据初始的参考位置)
q个操作后 输出与1~n编号的女孩跳舞的男孩的编号序列
题解:
我gou 码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int n,qq;
int ans[];
int mo(int qqq)
{return (qqq+*n)%n;}
int main()
{
int jj,ou,ke,k,gg;
scanf("%d %d",&n,&qq);
jj=;ou=;
for(int i=;i<=qq;i++)
{
scanf("%d",&k);
if(k==)
{
scanf("%d",&gg);
jj+=gg;
jj=mo(jj);
ou+=gg;
ou=mo(ou);
}
else
{
if((jj+n)%)
{
jj--;
jj=mo(jj);
ou++;
ou=mo(ou);
}
else
{
jj++;
jj=mo(jj);
ou--;
ou=mo(ou);
}
} }
for(int i=;i<=n;i++)
{
if(i%){
ke=i+jj;
ke=mo(ke);
ans[ke]=i;
}
else{
ke=i+ou;
ke=mo(ke);
ans[ke]=i;
}
}
for(int i=;i<n;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[]);
return ;
}
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D的更多相关文章
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
- 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 ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟
C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
- 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 ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- Hash学习笔记
啊啊啊啊,这篇博客估计是我最早的边写边学的博客了,先忌一忌. 本文章借鉴与一本通提高篇,但因为是个人的学习笔记,因此写上原创. 目录 谁TM边写边学还写这玩意? 后面又加了 Hash Hash表 更多 ...
- C# 实现窗口无边框,可拖动效果
#region 无边框拖动效果 [DllImport("user32.dll")]//拖动无窗体的控件 public static extern bool ReleaseCaptu ...
- go学习笔记-运算符
运算符 运算符 内置运算符 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 其他运算符 算术运算符 假定 A 值为 10,B 值为 20. 运算符 描述 实例 + 相加 A + B 输出结果 ...
- Codeforces 845 C Two TVs
参考:https://blog.csdn.net/xjh_shin/article/details/77491693 #include <iostream> #include <cs ...
- Java——Random类随机整数---18.10.11
一.Random类的定义 1.Random类位于java.util包中,主要用于生成 伪随机数 2.random类将 种子数 作为随机算法的起源数字,计算生成伪随机数,其与生成的随机数字的区间无关 3 ...
- onenet基础通信套件返回+CIS ERROR: 50的问题解决
1. 场景分析,主要问题就是有些操作返回+CIS ERROR: 50 2. 看了一下在AT+MIPLOBSERVERSP这个指令里面是没有返回+CIS ERROR: 50的错误类型的,所以应该是在解析 ...
- 史上最全的PHP正则表达式
首先看下正则表达式思维导图: 一.校验数字的表达式 1 数字:^[0-9]*$2 n位的数字:^\d{n}$3 至少n位的数字:^\d{n,}$4 m-n位的数字:^\d{m,n}$5 零和非零开头 ...
- Lambda方式左连接有Linq方式左连接
网上查到的直接使用Join+DefaultIfEmpty的方式是错误的,实际生成SQL是两表先内联接,然后再LEFT JOIN.经过查证,参考资料,最终得到如下两种方式的左连接写法: public v ...
- 网页设计简史看设计&代码“隔膜”
本文来自网易云社区 作者:马宝 设计与代码之间隔膜所在?既然你诚心诚意地问了,我就大发慈悲地告诉你.为了防止地球被破坏,为了维护世界的和平,为了贯彻爱与真实的邪恶~,我是穿梭在前端与设计之间爱与美丽的 ...
- springmvc基础篇—使用注解方式为前台提供数据
一.新建一个Controller package cn.cfs.springmvc.service; import java.util.ArrayList; import java.util.Hash ...