HDUOJ 6707 Shuffle Card

题目链接

Problem Description

A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for m times.

Please output the order of cards after m operations.

Input

The first line of input contains two positive integers n and m.(1<=n,m<=1e5)

The second line of the input file has n Numbers, a sequence of 1 through n.

Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-th operation.

Output

Please output the order of cards after m operations. (There should be one space after each number.)

Sample Input

5 3
1 2 3 4 5
3
4
3

Sample Output

3 4 1 2 5

思维题,在线洗牌肯定会 T,因为没有一个很好的数据结构可以完成此题。我们不妨换一种思维,把洗牌顺序记录下来,不难发现,最后一次洗的牌一定在第一张,倒数第二次在第二张,以此类推,我们标记一下洗过的牌,最后没洗的保持原顺序插入答案数组即可,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,m,a[N],op[N],vis[N];
vector<int>ans;
int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}for(int i=1;i<=m;i++) scanf("%d",&op[i]);for(int i=m;i>=1;i--){if(!vis[op[i]]){ans.push_back(op[i]);vis[op[i]]=1;}}for(int i=1;i<=n;i++){if(!vis[a[i]]) ans.push_back(a[i]);}for(auto i:ans) printf("%d ",i);
}

HDUOJ 6707 Shuffle Card相关推荐

  1. 2019中国大学生程序设计竞赛(CCPC)-网络选拔赛-第七题Shuffle Card

    文章目录 1.大赛题目 2.中文翻译 3.代码案例 4.解题思路 4.1代码举例 1.大赛题目 Shuffle Card Time Limit: 2000/1000 MS (Java/Others) ...

  2. 2019CCPC网络预选赛 八道签到题题解

    目录 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 6702 & 6703 array 6704 K-th occurrence 6705 path 6706 huntian o ...

  3. 你的斗地主能拿多少炸?

    2019独角兽企业重金招聘Python工程师标准>>> 最近无聊,想知道一下玩斗地主的话我能有多大的概率拿到炸弹(4张同点数牌 或 集齐大小王).但是我概率学学得不好,于是想到用统计 ...

  4. C#学习笔记(八)——定义类的成员

    一.成员的定义 1.定义字段 class Myclass{public int MyInt;} 可以使用readonly关键字,表示这个字段只能在执行构造函数的过程中赋值,或者由初始化语句赋值. 静态 ...

  5. Java Arrays.sort()的几种用法

    Java的Arrays类中有一个sort()方法,该方法是Arrays类的静态方法,在需要对数组进行排序时,非常的好用. 但是sort()的参数有好几种,下面我就为大家一一介绍,这几种形式的用法. = ...

  6. 2019CCPC网络选拔赛签到题题解

    前言 因为实力不济,没能通过网络赛拿到晋级的名额,心情沉重,故作此文记录本次网络赛的点滴收获.其中包含1001 ^ & ^.1006 Shuffle Card.1007 Windows Of ...

  7. java折叠自行车x1-auto,java入门第三季 7-1 简易扑克练习

    比较方法 import java.util.Comparator; public class CardComparator implements Comparator{ @Override publi ...

  8. C语言结构、联合、位操作、位域和枚举

    1.结构 结构是派生的数据类型,可以使用其他数据类型来构造它们. 1.1 定义结构和结构类型的变量 关键字struct引入了结构定义,用一个标识符作为结构标记,来命名一个结构类型.结构定义大括号内声明 ...

  9. 洗牌、发牌算法 (打乱扑克牌顺序)

      #include <stdio.h> #include <stdlib.h> #include <time.h> int  d[6]; int  i,n,a,b ...

最新文章

  1. 一次SQLSERVER触发器编写感悟
  2. 使用JQuery从客户端调用C#方法
  3. DL之ShuffleNet:ShuffleNet算法的简介(论文介绍)、架构详解、案例应用等配图集合之详细攻略
  4. 用shell脚本实现MongoDB数据库自动备份
  5. 在 SAP CRM Fiori 应用上给 Opportunity 订单添加 note 的后台执行明细
  6. jboss eap 7_使用JBoss EAP 7的HTTP / 2
  7. Liferay 部署war包时候的deployDirectory 细节分析
  8. spark学习-Spark算子Transformations和Action使用大全(Transformations章(二))
  9. 酷炫可视化+强于excel的结合体!超高效的表格工具,不用可惜
  10. 使用python来操作hive(通过 pyhs2 和 HiveServer2)
  11. HTML5定稿了,终于有一种编程语言开发的程序可以在Android和IOS两种设备上运行了...
  12. jquery之父john resig见面会及jquery最新动态
  13. python将嵌套列表转换为字典
  14. sdk环境变量配置不成功
  15. 如何保护自己的个人隐私
  16. 合同智能审核软件-提高审查效率和准确性
  17. Android手机总是提示:存储空间不足,解决方法
  18. html5css3选择题,web前端技术(HTML5+CSS3)答案试题题目及答案,期末考试题库,章节测验答案...
  19. pl_slam配置、运行过程
  20. python基础——3、python应用(日期、文件、词云统计)——(YZ)

热门文章

  1. 认清学习的本质 - 读《认知天性》
  2. c++实现运动目标的追踪
  3. 【转】一文带你了解ARM的发展历程
  4. MIT-BIH介绍(二)什么是MIT-BIH?
  5. 事件冒泡和事件捕获的区别
  6. matlab-K折交叉验证与分层K折交叉验证
  7. STM32 HAL库之IIC
  8. cpuz测试分数天梯图_联想Z5跑分实测 附高通骁龙636天梯图性能排名
  9. 通过百度人脸对比API进行人脸对比
  10. 电子器件系列26:el 375n光耦 电气特性参数