2019ICPC南昌网络赛 E 双端队列模拟

直接搞自闭的一道题。

题目连接

思路

模拟一个双端队列,双端队列反推摸牌过程,最后双端队列可以当作数组用,直接输出对应标号即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <queue>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
int n, m;
int T;
cin >> T;
while(T--)
{
scanf("%d %d",&n,&m);
int value = n,q;
deque<int>Q;
while(Q.size() < n - 1)
{
Q.push_front(value--);
int num = m;
while(num--)
{
Q.push_front(Q.back());
Q.pop_back();
}
}
Q.push_front(1);
cin >> q;
for(int i = 1; i <= q; ++i)
{
int x; cin >> x;
cout << Q[x - 1] << '\n';
}
}
}