跳到正文

个人记录

蒟蒻的来做梦7.5总结

__IE14约 9 分钟
原文
文章信息与版本

文章信息

发布
2025年7月6日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 9 分钟

版本

  1. v1当前

应该没人写了笔记吧但还是放一个黑板:
上课黑板图片
tips:斜体为踩过的坑

T627216 周末舞会

水题,手写queue,记得跳完要排回去

C++
#include<iostream>

using namespace std;
int n,m,k;
class my_queue{
public:
	void push(int p){
		q[r++]=p;
	}
	void pop(){
		l++;
	}
	int front(){
		return q[l];
	}
private:
	int l,r;
	int q[10000];
};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n>>m>>k;
	my_queue qm,qw;
	for(int i=1;i<=n;i++){
		qm.push(i);
	}
	for(int i=1;i<=m;i++){
		qw.push(i);
	}
	for(int i=1;i<=k;i++){
		cout<<qm.front()<<' '<<qw.front()<<'\n';
		qm.push(qm.front());
		qw.push(qw.front());
		qm.pop();
		qw.pop();
	}
	return 0;
}

T627222 围圈报数

水题*2,约瑟夫简化。

C++
#include<iostream>

using namespace std;
int n,m;
class my_queue{
public:
	void push(int p){
		q[r++]=p;
	}
	void pop(){
		l++;
	}
	int front(){
		return q[l];
	}
	int size(){
		return r-l;
	}
private:
	int l,r;
	int q[10000];
};
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n>>m;
	my_queue q;
	for(int i=1;i<=n;i++){
		q.push(i);
	}
	while(q.size()){
		for(int i=1;i<m;i++){
			q.push(q.front());
			q.pop();
		}
		cout<<q.front()<<' ';
		q.pop();
	}
	return 0;
}

P1090 [NOIP 2004 提高组] 合并果子

贪心算法,先合小的,可用堆,小根堆,二叉堆|配对堆,实现手写|STL|pbds优先队列假队列实现

C++
#include<iostream>
#include<queue>
using namespace std;
int n,cnt;
priority_queue<int,vector<int>,greater<int>>pq;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;i++){
		int f;
		cin>>f;
		pq.push(f);
	}
	while(pq.size()>1){
		int pf=pq.top();
		pq.pop();
		pf+=pq.top();
		pq.pop();
		pq.push(pf);
		cnt+=pf;
	}
	cout<<cnt;
	return 0;
}

P5724 【深基4.习5】求极差 / 最大跨度值 / 最大值和最小值的差

大 炮 打 蚊 子

C++
#include<iostream>
#include<queue>
using namespace std;
int n;
priority_queue<int,vector<int>,greater<int>>pqmin;
priority_queue<int>pqmax;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;i++){
		int f;
		cin>>f;
		pqmin.push(f);
		pqmax.push(f);
	}
	cout<<pqmax.top()-pqmin.top();
	return 0;
}

P2952 [USACO09OPEN] Cow Line S

双端队列板子题。

C++
#include<iostream>
#include<deque>
using namespace std;
int s;
deque<int>dq;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>s;
	int rp=1;
	for(int i=1;i<=s;i++){
		char c;
		cin>>c;
		if(c=='A'){
			cin>>c;
			if(c=='L'){
				dq.push_front(rp++);
			}else{
				dq.push_back(rp++);
			}
		}else{
			int k;
			cin>>c>>k;
			if(c=='L'){
				for(int t=1;t<=k;t++){
					dq.pop_front();
				}
			}else{
				for(int t=1;t<=k;t++){
					dq.pop_back();
				}
			}
		}
	}
	for(auto i:dq){
		cout<<i<<'\n';
	}
	return 0;
}

B3616 【模板】队列

板子。

C++
#include<iostream>
#include<queue>
using namespace std;
int n;
queue<int>q;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;i++){
		int f;
		cin>>f;
		switch(f){
			case 1:{
				cin>>f;
				q.push(f);
				break;
			}
			case 2:{
				if(q.empty()){
					cout<<"ERR_CANNOT_POP\n";
					break;
				}
				q.pop();
				break;
			}
			case 3:{
				if(q.empty()){
					cout<<"ERR_CANNOT_QUERY\n";
					break;
				}
				cout<<q.front()<<'\n';
				break;
			}
			case 4:{
				cout<<q.size()<<'\n';
				break;
			}
		}
	}
	return 0;
}

P3887 [GDOI2014] 世界杯

机 枪 打 蚊 子

用假队列给该队空闲最强的内核队员,然后算平均数。

C++
#include<iostream>
#include<iomanip>
#include<queue>
using namespace std;
int k,d,m,f,q;
priority_queue<int>pqk,pqd,pqm,pqf;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cin>>k>>d>>m>>f;
	for(int i=1;i<=k;i++){
		int l;
		cin>>l;
		pqk.push(l);
	}
	for(int i=1;i<=d;i++){
		int l;
		cin>>l;
		pqd.push(l);
	}
	for(int i=1;i<=m;i++){
		int l;
		cin>>l;
		pqm.push(l);
	}
	for(int i=1;i<=f;i++){
		int l;
		cin>>l;
		pqf.push(l);
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		int a,b,c,ssid=pqk.top();
		cin>>a>>b>>c;
		pqk.pop();
		for(int i=1;i<=a;i++){
			ssid+=pqd.top();
			pqd.pop();
		}
		for(int i=1;i<=b;i++){
			ssid+=pqm.top();
			pqm.pop();
		}
		for(int i=1;i<=c;i++){
			ssid+=pqf.top();
			pqf.pop();
		}
		cout<<fixed<<setprecision(2)<<static_cast<double>(ssid)/(1+a+b+c)<<'\n';
	}
	return 0;
}

本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用

原文