题目链接:https://vjudge.net/problem/HDU-6707

题意:给你一个数组a[ ](a[1]=1,a[2]=2.....a[n]=n),然后m次操作,每次把那个数拿到最前面去,问最后数列的顺序。

思路:因为最前的数肯定是最后一次操作的数,那么我们只要重后往前遍历即可,为了防止重复出现,用个vis数组维护一下。

  1 #include <bits/stdc++.h>
2 #include <time.h>
3 #include <set>
4 #include <map>
5 #include <stack>
6 #include <cmath>
7 #include <queue>
8 #include <cstdio>
9 #include <string>
10 #include <vector>
11 #include <cstring>
12 #include <utility>
13 #include <cstring>
14 #include <iostream>
15 #include <algorithm>
16 #include <list>
17 using namespace std;
18 //cout<<setprecision(10)<<fixed;
19 #define eps 1e-6
20 #define PI acos(-1.0)
21 #define lowbit(x) ((x)&(-x))
22 #define zero(x) (((x)>0?(x):-(x))<eps)
23 #define mem(s,n) memset(s,n,sizeof s);
24 #define rep(i,a,b) for(int i=a;i<=b;i++)
25 #define rep2(i,a,b) for(int i=a;i>=b;i--)
26 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
27 typedef long long ll;
28 typedef unsigned long long ull;
29 const int maxn=1e6+5;
30 const ll Inf=0x7f7f7f7f7f7f7f;
31 const ll mod=1e6+3;
32 //const int N=3e3+5;
33 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
34 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
35 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
36 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
37 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
38 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
39 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
40 inline int read()
41 {
42 int X=0; bool flag=1; char ch=getchar();
43 while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
44 while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
45 if(flag) return X;
46 return ~(X-1);
47 }
48 inline void write(int X)
49 {
50 if(X<0) {X=~(X-1); putchar('-');}
51 if(X>9) write(X/10);
52 putchar(X%10+'0');
53 }
54 /*
55 inline int write(int X)
56 {
57 if(X<0) {putchar('-'); X=~(X-1);}
58 int s[20],top=0;
59 while(X) {s[++top]=X%10; X/=10;}
60 if(!top) s[++top]=0;
61 while(top) putchar(s[top--]+'0');
62 }
63 */
64 int Abs(int n) {
65 return (n ^ (n >> 31)) - (n >> 31);
66 /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
67 若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
68 需要计算 n 和 -1 的补码,然后进行异或运算,
69 结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
70 }
71 ll binpow(ll a, ll b) {
72 ll res = 1;
73 while (b > 0) {
74 if (b & 1) res = res * a%mod;
75 a = a * a%mod;
76 b >>= 1;
77 }
78 return res%mod;
79 }
80 void extend_gcd(ll a,ll b,ll &x,ll &y)
81 {
82 if(b==0) {
83 x=1,y=0;
84 return;
85 }
86 extend_gcd(b,a%b,x,y);
87 ll tmp=x;
88 x=y;
89 y=tmp-(a/b)*y;
90 }
91 ll mod_inverse(ll a,ll m)
92 {
93 ll x,y;
94 extend_gcd(a,m,x,y);
95 return (m+x%m)%m;
96 }
97 ll eulor(ll x)
98 {
99 ll cnt=x;
100 ll ma=sqrt(x);
101 for(int i=2;i<=ma;i++)
102 {
103 if(x%i==0) cnt=cnt/i*(i-1);
104 while(x%i==0) x/=i;
105 }
106 if(x>1) cnt=cnt/x*(x-1);
107 return cnt;
108 }
109 int a[maxn],b[maxn],vis[maxn];
110 int n,m;
111 int main()
112 {
113 n=read();
114 m=read();
115 for(int i=1;i<=n;i++) a[i]=read();
116 for(int i=1;i<=m;i++) b[i]=read();
117 for(int i=m;i>=1;i--)
118 {
119 if(!vis[b[i]])
120 {
121 printf("%d ",b[i]);
122 vis[b[i]]=1;
123 }
124 }
125 for(int i=1;i<=n;i++)
126 {
127 if(!vis[i])
128 printf("%d ",i);
129 }
130 return 0;
131 }

Shuffle Card HDU - 6707的更多相关文章

  1. CCPC 2019 网络赛 1006 Shuffle Card

    // 签到题,比赛时候写双向链表debug了半天,发现有更好方法,记录一下.   Shuffle Card HDU 6707 题意:   有一 \(n\) 张卡片,编号 \(1~n\) ,给定初始编号 ...

  2. card card card HDU - 6205

    As a fan of Doudizhu, WYJ likes collecting playing cards very much. One day, MJF takes a stack of ca ...

  3. 2019CCPC网络赛

    ^&^ (HDU 6702) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  4. M面经prepare: Shuffle a deck

    设计一个shuffle card 用了java. Random Class package Random; import java.util.*; public class Solution { st ...

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

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

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

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

  7. python基础(14)-反射&类的内置函数

    反射 几个反射相关的函数可参考python基础(10)-匿名函数&内置函数中2.2.4反射相关 类的一些内置函数 __str__()&__repr__() 重写__str__()函数类 ...

  8. C#入门经典第十章例题 - - 卡牌

    1.库 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  9. C++分享笔记:扑克牌的洗牌发牌游戏设计

    笔者在大学二年级期间,做过的一次C++程序设计:扑克牌的洗牌发牌游戏.具体内容是:除去大王和小王,将52张扑克牌洗牌,并发出5张牌.然后判断这5张牌中有几张相同大小的牌,是否是一条链,有几个同花等. ...

随机推荐

  1. sqli-libs(4) 双引号报错

    经测试,发现单引号不报错,而双引号却报错了 通过查看源码,发现下图中红色的箭头,如果不知道是什么意思,我们可以复制出来看看是什么含义: <?php$id=1;$id='"' .$id. ...

  2. u-boot 移植 --->1、u-boot配置(Kbuild)

    早期的U-BOOT的裁剪是没有使用Kbuild工具的,后来就借鉴了Linux的Kbuild同时也是方便使用者裁剪,因为他的原理和Linux内核的配置裁剪原理是相同的.今天拿来分析的U-Boot的版本是 ...

  3. [转]论基于DSSA的软件架构设计与应用

    [摘要]   去年三月份,我所在的公司启动国网电力用户用电信息采集系统项目,我被任命为项目负责人.国网电力用户用电信息采集系统是国家电网公司坚强智能电网建设的一部分.由于公司之前为南网(主要是广东省) ...

  4. TypeScript & Canvas 实现可视化白板

    TypeScript & Canvas 实现可视化白板 https://excalidraw.com/ https://github.com/excalidraw/excalidraw ref ...

  5. SVG in Action

    SVG in Action HTML5 semantic HTML5 Semantic Elements / HTML5 Semantic Tags figure object <figure& ...

  6. 使用 js 实现十大排序算法: 归并排序

    使用 js 实现十大排序算法: 归并排序 归并排序 refs js 十大排序算法 All In One https://www.cnblogs.com/xgqfrms/p/13947122.html ...

  7. SEO All In One

    SEO All In One website SEO https://www.google.com/search?newwindow=1&safe=active&sxsrf=ALeKk ...

  8. how to change sketch language to chinese

    how to change sketch language to Chinese https://www.sketch.com/support/troubleshooting/chinese-loca ...

  9. 2020 新型肺炎病毒疫情 & 远程办公

    2020 新型肺炎病毒疫情 & 远程办公 2020 新型肺炎病毒疫情 https://zhuanlan.zhihu.com/p/104406687 钉钉 微信 code gitlab PRD ...

  10. Nestjs 验证对象数组

    route @Patch(':id') patch(@Param('id') id: string, @Body() removeEssayDto: RemoveEssayDto) { return ...