cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n, d, k;
int const N = 1000010;
typedef pair<int, int> pii;
bool st[N];
int cnt[N];
pii logs[N];
int main()
{
cin >> n >> d >> k;
for (int i = 1;i <= n;i++)
{
cin >> logs[i].first >> logs[i].second;
}
sort(logs + 1, logs + 1 + n);
for (int i = 1, j = 1;i <= n;i++)
{
cnt[logs[i].second]++;
while (logs[j].first + d <= logs[i].first)
{
cnt[logs[j].second]--;
j++;
}
if (cnt[logs[i].second] >= k)st[logs[i].second] = true;
}
for (int i = 0;i <= N;i++)
{
if (st[i])
{
cout << i << endl;
}
}
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<queue>
#include<cstring>
int n, r, c;
int ans1[210][210];
char arr[210][210];
bool use[210][210];
typedef pair<int, int> PII;
int dx[] = { 0,0,-1,1 };
int dy[] = { -1,1,0,0 };
int bfs(int x, int y)
{
PII pii;
queue<PII>q;
ans1[x][y] = 0;
memset(use, 0, sizeof(use));
pii.first = x;
pii.second = y;
q.push(pii);
while (!q.empty()) //RCCC
{ //RCCC
; //RCCC
if (arr[q.front().first][ q.front().second] == 'E')
{
return ans1[q.front().first][q.front().second];
}
else
{
for (int i = 0;i < 4;i++)
{
if (use[q.front().first + dx[i]][q.front().second + dy[i]])continue;
if (q.front().first + dx[i] > r || q.front().first + dx[i] < 1)continue;
if (q.front().second + dy[i] > c || q.front().second + dy[i] < 1)continue;
if (arr[q.front().first + dx[i]][ q.front().second + dy[i]] == '#')continue;
pii.first = q.front().first + dx[i];
pii.second = q.front().second + dy[i];
ans1[q.front().first + dx[i]][q.front().second + dy[i]] = ans1[q.front().first ][q.front().second ] + 1;
use[q.front().first + dx[i]][ q.front().second+dy[i]] = true;
q.push(pii);
}
}
q.pop();
}
return -1;
}
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
int sx, sy;
cin >> r >> c;
for (int j = 1;j <= r;j++)
{
for (int z = 1;z <= c;z++)
{
cin >> arr[j][z];
if (arr[j][z] == 'S')
{
sx = j;
sy = z;
}
}
}
int ans = bfs(sx, sy);
if (ans == -1)
{
cout << "oop!" << endl;
}
else cout << ans << endl;
}
return 0;
}
cpp
#include<iostream>
using namespace std;
int const N = 10010;
bool use[N];
int logs[N];
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
{
use[i] = true;
cin >> logs[i];
}
int ans = 0;
for (int i = 1;i <= n;i++)
{
if (!use[i])continue;
use[i] = false;
int flag = logs[i];
while (flag != i)
{
use[flag] = false;
flag = logs[flag];
ans++;
}
}
cout << ans << endl;
return 0;
}