海港 / 洛谷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;
}

https://www.cnblogs.com/Little-Turtle--QJY/p/12599887.html

posted @ 2020-08-08 13:09  LT-Y  阅读(96)  评论(0)    收藏  举报