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 }

原文地址:https://www.cnblogs.com/SSummerZzz/p/11512319.html

时间: 2024-08-30 16:40:55

The 2019 Asia Nanchang First Round Online Programming Contest E. Magic Master的相关文章

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

This is an era of team success, but also an era of heroes. Throughout the ages, there have been numerous examples of using the few to defeat the many. There are VV(Numbers 11 to VV) fire-fighting points in ACM city. These fire-fighting points have EE

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

Long long ago, the sky and the earth were not separated, and the universe was chaotic. There was a giant named Pangu who slept for eighteen thousand years in this chaos. One day, Pangu woke up suddenly. When he saw the darkness around him, he took up

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

题意:https://nanti.jisuanke.com/t/41355 给出N1,计算公式:A=F(N)Ni=Ni-1 ^ (A*A),F为类斐波那契需要矩阵快速幂的递推式. 求第k个N. 思路: 发现从大约1e5个数开始N交替出现,到一定位置%2即可.(or正解:https://blog.csdn.net/qq_41848675/article/details/100667808   or https://blog.csdn.net/jk_chen_acmer/article/detail

The 2019 Asia Nanchang First Round Online Programming Contest The Nth Item

The Nth Item 思路: 先用特征根法求出通向公式,然后通向公式中出现了\(\sqrt{17}\),这个可以用二次剩余求出来,然后可以O(\(log(n)\))求出. 但是还不够,我们先对\(n\)欧拉降幂,然后求base为\(\sqrt{1e9}\)的快速幂,预处理一些东西,就可以类似O(1)求出了. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/std

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

思路:矩阵快速幂+map 代码: #include<cmath> #include<algorithm> #include<cstdio> #include<map> const int INF=0x3f3f3f3f; const int maxn = 1e7+10; const int mod=998244353; using namespace std; typedef long long ll; map<ll,ll> mp; ll n; s

The 2019 Asia Yinchuan First Round Online Programming F. Moving On

t题目链接:https://nanti.jisuanke.com/t/41290 思路:题目意思很容易想到floyd,但是由于危险度的限制,我们该怎么跑floyd呢. 一开始理解错题目了,以为u->v包括终点起点都不能超过给的危险度,不过看样例,好像只需要中间的城市不能超过危险度. 我们可以这么想,每个城市都有一个危险度,而floyd算法的本质是i到j经过前k个城市的转移,得到多源最短路,那么我们不妨 记录城市的编号和危险度,然后按城市的危险度排序,重新编号,危险度小的先跑floyd,然后f[k

2019 ICPC Universidad Nacional de Colombia Programming Contest

https://codeforc.es/gym/102307 最后5题收尾了,大概率铜.其中有2题是签到手速题.有一题是抄模板的表达式求值,写一个分数类随便过. 比较有趣的是下面的: G. Graduation 题意:一共有n门课,每门课有至多1门先修课,没有先修课的用0表示.学习一门课的条件是:这个学期选的课不足k门,且这门课的先修课(假如有的话)已经在前面的学期中学过了.求最少需要多少个学期学完. 思路:队友一开始是优先拓展儿子数最多的子结点,我觉得怪怪的,比如一个像蒲公英一样的东西,一开始

[AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

[AtCoder] NIKKEI Programming Contest 2019 ??本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder. A - Subscribers ??首先始终 \(max = \min(A, B)\) ,\(min\) 的话如果 \(A + B \leq N\) ,那么就是 \(0\) ,否则就是 \(A + B - N\) . int n, a, b; int main() { read(n), read

【AtCoder】diverta 2019 Programming Contest

diverta 2019 Programming Contest 因为评测机的缘故--它unrated了.. A - Consecutive Integers #include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define