浪在ACM 集训队第十次测试赛

 

A  Diverse Substring

B  Vasya and Books

C  Birthday

D  LCM

 

A 传送门

  题解

 

B 传送门

题解:  

  这道题,就比较简单了,直接用队列模拟一下就好了,话不多说,上代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 #define mem(a,b) memset(a,b,sizeof(a))
 6 const int maxn=2e5+10;
 7 
 8 int n;
 9 int a[maxn];
10 bool inStack[maxn];//inStack[i]:判断数i是否再栈中
11 
12 int main()
13 {
14     scanf("%d",&n);
15     for(int i=1;i <= n;++i)
16         scanf("%d",a+i);
17     mem(inStack,true);
18     int index=1;
19     for(int i=1;i <= n;++i)
20     {
21         int b;
22         scanf("%d",&b);
23         if(!inStack[b] || index > n)//如果b不在栈中
24         {
25             printf("0\n");
26             continue;
27         }
28         
29         int res=0;
30         while(a[index] != b)
31         {
32             inStack[a[index++]]=false;
33             res++;
34         }
35         inStack[a[index++]]=false;
36         printf("%d\n",++res);
37     }
38     return 0;
39 }
View Code

相关文章:

  • 2021-06-06
  • 2021-05-23
  • 2021-06-21
  • 2021-12-06
  • 2021-07-25
  • 2021-11-04
  • 2021-08-22
猜你喜欢
  • 2022-02-27
  • 2021-10-31
  • 2021-08-10
  • 2022-01-24
  • 2022-01-14
  • 2021-11-08
  • 2021-12-14
相关资源
相似解决方案