第十四届蓝桥杯三月真题刷题训练——第 9 天(3.12)

杨枝 杨枝
C/C++领域新星创作者
2023-03-12 20:21:50

1\

#include <bits/stdc++.h>
#define mpr make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N  = 1e7 + 10;
int cnt;
ll primes[N];
bool st[N];

void get_primes(int n)
{
	//枚举所有的数 
	for(ll i = 2;i <= n;i++)
	{
		if(!st[i]) primes[cnt++] = i;
		
		//要的是质数,得在当前的质数范围中 
		for(int j = 0;primes[j]<= n/i;j++)
		{
			st[primes[j]* i] = 1;
			if(i % primes[j] == 0) break;
		}
	}
}



//100002 
void solve(){
	get_primes(N);
	cout << primes[100001];
}

void run()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

int main() {
	run();
	int t;
	t = 1;
	
	while(t--) {
		solve();
	}

	return 0;
}

 

2\

#include <bits/stdc++.h>
#define mpr make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N  = 1e5 + 10;
int a[] = {1,2,3,4,5,6,7,8,9,10};
ll cnt = 0;

void solve(){
	do{
//		for(int i = 0;i < 9;i++)
//		{
//			cout << a[i] <<" ";
//		}
//		cout <<endl;
		cnt ++;
	}while(next_permutation(a,a+10));
	cout << cnt;
}

void run()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

int main() {
	run();
	int t;
	t = 1;
	
	while(t--) {
		solve();
	}

	return 0;
}

3\脑子不在线,调试不出来

#include <bits/stdc++.h>
#define mpr make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N  = 1e5 + 10;
int cnt[N];//统计帖子点赞数量 
bool st[N];
struct Node{
	int ts,id;
}node[N]; 

//按照时间排序 
bool cmp(Node a,Node b)
{
//	if(a.ts == b.ts) return a.id < b.id;
	return a.ts < b.ts;
}
int n,d,k;

void solve(){
	cin >> n >> d >> k;
	for(int i = 0;i < n;i++)
	{
		cin >> node[i].ts >> node[i].id;
	}
	sort(node,node+n,cmp);
	
	int j = 0;
	for(int i = 0;i < n;i++)
	{
		//拿到当前时间下的帖子编号
		cnt[node[i].id] ++; 
		
		//拿时间来做双指针 ,如果当前时间大于等于之前某个时间的差值d,那么这份比较久的帖子报废 了 
		while(node[i].ts - node[j].ts >= d)
		{
			cnt[node[j].id] --;
			j++;
			//统计是热帖的 
			if(cnt[node[i].id] >= k) st[node[i].id] = true;
		}
	}
	
	for(int i = 0;i <= N;i++)
	{
		if(st[i]) cout << i<< endl;
	}
}

void run()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

int main() {
	run();
	int t;
	t = 1;
	
	while(t--) {
		solve();
	}

	return 0;
}

 

...全文
19 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,854

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧