洛谷P1540 机器翻译

参考代码

cpp 复制代码
#include<iostream>
#include<queue>
using namespace std;
int nums[1010];
int main(){
	queue<int> q;
	int M,N;
	cin>>M>>N;
	int res=0;
	while(N--){
		int tmp;
		cin>>tmp;
		if(nums[tmp]==1)
			continue;
		if(q.size()<M){
			q.push(tmp);
			res++;
			nums[tmp]=1;
		}
		if(q.size()==M&&nums[tmp]==0){
			nums[q.front()]=0;
			q.pop();
			q.push(tmp);
			nums[tmp]=1;
			res++;
		}
	}
	cout<<res<<endl;
    return 0;
}

题目链接

1540 机器翻译

相关推荐
weixin_307779137 分钟前
PySpark实现ABC_manage_channel逻辑
开发语言·python·spark
莹莹学编程—成长记1 小时前
string的模拟实现
服务器·c++·算法
??? Meggie1 小时前
【Python】保持Selenium稳定爬取的方法(防检测策略)
开发语言·python·selenium
酷爱码3 小时前
如何通过python连接hive,并对里面的表进行增删改查操作
开发语言·hive·python
画个大饼3 小时前
Go语言实战:快速搭建完整的用户认证系统
开发语言·后端·golang
喵先生!4 小时前
C++中的vector和list的区别与适用场景
开发语言·c++
Thomas_YXQ5 小时前
Unity3D Lua集成技术指南
java·开发语言·驱动开发·junit·全文检索·lua·unity3d
xMathematics5 小时前
计算机图形学实践:结合Qt和OpenGL实现绘制彩色三角形
开发语言·c++·qt·计算机图形学·cmake·opengl
ShiinaMashirol6 小时前
代码随想录打卡|Day27(合并区间、单调递增的数字、监控二叉树)
java·算法
yuanManGan7 小时前
C++入门小馆: 深入了解STLlist
开发语言·c++