# 第十四届蓝桥杯三月真题刷题训练——第 9 天（3.12）

``````#include <iostream>

using namespace std;

const int N = 100010;

int cnt;

bool check(int x)
{
for (int i = 2; i <= x / i; i ++ )
if (x % i == 0)
return false;
return true;
}

int main()
{
for (int i = 2; ; i ++ )
{
if (check(i)) cnt ++ ;
if (cnt == 100002)
{
cout << i << endl;
return 0;
}
}
return 0;
}``````

``````#include <iostream>

using namespace std;

const int N = 1e6;
int primes[N], cnt;
bool st[N];

void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i;
for (int j = 0; primes[j] <= n / i; j ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}

int main()
{
get_primes(N - 1);
int res = 0;
for (int i = 2; ; i ++ )
{
if (!st[i]) res ++ ;
if (res == 100002)
{
cout << i << endl;
return 0;
}
}
return 0;
}``````

``````#include <iostream>
#include <algorithm>

using namespace std;

const int N = 15;

int num[N];
int ans;

bool check()
{
for (int i = 0; i < 9; i ++ )
if (abs(num[i + 1] - num[i]) == 1) return false;

return true;
}

int main()
{
for (int i = 0; i < 10; i ++ ) num[i] = i + 1;
do {
if (check()) ans ++ ;
}while (next_permutation(num, num + 10));

cout << ans << endl;
}``````

``````#include <bits/stdc++.h>

using namespace std;

const int N = 100010;

struct ret{
int id;
int ts;
}p[N];

int n, d, k;
int cnt[N];
bool st[N];

int main()
{
scanf("%d%d%d", &n, &d, &k);
for (int i = 0; i < n; i ++ ) cin >> p[i].ts >> p[i].id;

sort(p, p + n, [&](ret a, ret b){
return a.id < b.id;
});

for (int i = 0, j = 0; i < n; i ++ )
{
auto id = p[i].id;
cnt[id] ++ ;

while (j < i && p[i].ts - p[j].ts >= d)
{
cnt[p[j].id] -- ;
j ++ ;
}
if (cnt[id] >= k) st[id] = true;
}

for (int i = 0; i < N; i ++ )
if (st[i]) cout << i << endl;

return 0;
}``````

...全文
17 回复 打赏 收藏 转发到动态 举报

50,804

• 近7日
• 近30日
• 至今

刷题！