The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master

Posted ssummerzzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master相关的知识,希望对你有一定的参考价值。

题目链接:https://nanti.jisuanke.com/t/41352

题目意思还是好理解的,看过的人不多,感觉是被通过量吓到了。其实就是个水题,反向模拟就好了,

用队列模拟,反向模拟,它要放m张卡到后面,那我就放m张卡到前面,一开始队列只有1张卡,慢慢加到n张卡,

先加大的卡,再一直到1的卡。对了,可能会出现只有5张卡,m却是6,7,8或9,10,那么为了减少不必要的模拟,

用mod来减少,因为有些模拟会让卡和之前比较,算是原封不动。


 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <queue>
 6 #include <stack>
 7 #include <string>
 8 #include <map>
 9 #include <cmath>
10 #include <iomanip>
11 using namespace std;
12  
13 typedef long long LL;
14 #define inf 1e9
15 #define rep(i,j,k) for(int i = (j); i <= (k); ++i)
16 #define rep__(i,j,k) for(int i = (j); i < (k); ++i)
17 #define per(i,j,k) for(int i = (j); i >= (k); --i)
18 #define per__(i,j,k) for(int i = (j); i > (k); --i) 
19 
20 const int N = 40000010;
21 int arr[N];
22 int mod,n,q;
23 queue<int> que;
24 
25 void work()
26 
27     int tmp;
28     que.push(n);//压入最大的卡
29     int num = 1;
30     int end = n - 1;//最后1的卡直接是取走的,所以那一轮不需要模拟了
31     while(num <= end)
32         tmp = mod % num;
33 
34         rep(o,1,tmp)
35             que.push(que.front());
36             que.pop();
37         
38         que.push(n-num);//压入前一张卡
39         ++num;
40     
41 //    que.push(1);
42 
43 
44 int main()
45 
46     int T;
47     scanf("%d",&T);
48 
49     while(T--)
50         scanf("%d%d",&n,&mod);
51 
52         rep(i,1,n)
53             arr[i] = i;//1-n的卡
54         
55         scanf("%d",&q);
56 
57         work();
58 
59         per(i,n,1)//取出卡
60             arr[i] = que.front();
61             que.pop();
62         
63 
64         int o;
65         rep(i,1,q)
66             scanf("%d",&o);
67             printf("%d\n",arr[o]);
68         
69 
70 //       rep(i,1,n) printf("%d ",arr[i]);
71     
72 
73     getchar(); getchar();
74     return 0;
75 

 

以上是关于The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master的主要内容,如果未能解决你的问题,请参考以下文章

Fire-Fighting Hero (The 2019 Asia Nanchang First Round Online Programming Contest)

H. The Nth Item(The 2019 Asia Nanchang First Round Online Programming Contest)

Pangu Separates Heaven and Earth(签到题)(The 2019 Asia Nanchang First Round Online Programming Contest)

The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master

The 2019 Aisa Nanchang First Round Online Programming Contest ——H

The 2019 ICPC China Nanchang National Invitational and International Silk-Road Programming Contest E