洛谷 P2058 海港(模拟)

题目链接:https://www.luogu.com.cn/problem/P2058

这是一道用手写队列模拟的一道题,没有什么细节,只是注意因为数不会很大,所以直接用数作为数组下标即可,不用用map映射。

AC代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 const int maxn=1000005;
 7 int n,head,tot,b[maxn],ans;
 8 
 9 struct node{
10     int ti,id;
11 } a[maxn];
12 
13 int main(){
14     scanf("%d",&n);
15     for(int i=1;i<=n;i++){
16         int t,k,x;
17         scanf("%d%d",&t,&k);
18         while(k--){
19             scanf("%d",&x);
20             a[++tot].id=x;
21             a[tot].ti=t;
22             if(b[x]==0) ans++;
23             b[x]++;
24         }
25         while(t-a[head].ti>=86400){
26             x=a[head].id;
27             b[x]--;
28             if(b[x]==0) ans--;
29             head++;
30         }
31         printf("%d
",ans);
32     }
33     return 0;
34 }
AC代码
原文地址:https://www.cnblogs.com/New-ljx/p/12236737.html