标签:stream com define printf i++ www algo 区间 ret
题目链接:
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\n",i); return 0; }
标签:stream com define printf i++ www algo 区间 ret
原文地址:https://www.cnblogs.com/doubest/p/12378618.html