[蓝桥杯2018初赛]日志统计-双指针
生活随笔
收集整理的這篇文章主要介紹了
[蓝桥杯2018初赛]日志统计-双指针
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
#include <iostream> #include <algorithm> using namespace std; typedef pair<int, int>PII; #define x first #define y second const int N = 100010; bool st[N]; int n, d, k; PII a[N]; int cnt[N];int main() {cin >> n >> d >> k;for (int i = 0, j = 0; i < n; i++)cin >> a[i].x >> a[i].y;sort(a, a + n);for (int i = 0, j = 0; i < n; i++) {cnt[a[i].y]++;while (a[i].x - a[j].x >= d) {cnt[a[j].y]--;j++;}if (cnt[a[i].y] >= k)st[a[i].y] = true;}for (int i = 0; i < N; i++) {if (st[i])cout << i << endl;}return 0; }總結
以上是生活随笔為你收集整理的[蓝桥杯2018初赛]日志统计-双指针的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: png转ico和.ico转.png格式
- 下一篇: QQ消息防撤回