海港 / 洛谷P2058
题目
https://www.luogu.com.cn/problem/P2058
CODE
队列 + 结构体
/连接 在 文末/
#include <bits/stdc++.h>
using namespace std;
#define For(a, b, c, d) for(int a = b; c <= d; a++)
struct node{
int times, country;
}P[100001];
int n, t, k, a, ans;
queue<node> que;
int main(){
scanf("%d", &n);
node Q;
Q.times = 0, Q.country = 0;
que.push(Q);
int bo[300001] = {0};
For(i, 1, i, n){
scanf("%d%d", &t, &k);
For(j, 1, j, k){
scanf("%d", &a);
Q.times = t, Q.country = a;
que.push(Q);
bo[a]++;
if(bo[a] == 1){//这个国籍是新的
ans++;
}
}
while(!que.empty()){//从头遍历,弹出不符合条件的船
Q = que.front();
if(Q.times <= (t-86400)){
bo[Q.country]--;
if(!bo[Q.country]){//这个国籍已经没有了
ans--;
}
que.pop();
}else{
printf("%d\n", ans);
break;
}
}
}
return 0;
}
没有未来的未来不是我想要的未来

浙公网安备 33010602011771号