zoukankan      html  css  js  c++  java
  • 1238. 日志统计

    题目链接:

    https://www.acwing.com/problem/content/1240/

    题解:

    双指针算法,注意率先移动前向的指针,当前向指针的时间-后向指针的时间超过了规定时间的话,后项指针要移动到该区间里才行

    AC代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define x first
    #define y second
    using namespace std;
    
    typedef pair<int,int> PII;
    const int N = 1e5+10;
    
    PII logs[N];
    bool st[N];
    int cnt[N];
    int n,d,k;
    
    int main(){
        scanf("%d%d%d",&n,&d,&k);
        for(int i = 0;i<n;i++) scanf("%d%d",&logs[i].x,&logs[i].y);
        sort(logs,logs+n);
        
        for(int i=0,j=0;i<n;i++){
            int id = logs[i].y;
            cnt[id]++;
            while(logs[i].x - logs[j].x >= d){
                cnt[logs[j].y]--;
                j++;
            }
            
            if(cnt[id] >= k) st[id] = true;
        }
        
        for(int i=0;i<N-1;i++)
            if(st[i]) printf("%d
    ",i);
        
        return 0;
    }
  • 相关阅读:
    __get__,__set__,__delete__
    __getattr__,__setattr__,__delattr__
    json ,pickle
    @property
    类的封装
    super
    继承顺序
    派生组合示例
    类的派生,组合
    class 属性查找
  • 原文地址:https://www.cnblogs.com/doubest/p/12378618.html
Copyright © 2011-2022 走看看