跳到正文

题解

题解 P1540 【机器翻译】

国民小仙女约 1 分钟
原文
文章信息与版本

文章信息

发布
2018年9月30日
收录
2026年2月24日
更新
2026年10月13日
篇幅
约 1 分钟
题目
P1540

版本

  1. v1当前

第一次发题解emmm #include<iostream> #include<queue>

using namespace std;

queue<int>h;

int m,n,ans,t,x,sum;

bool w[1005];

int main() {

cin>>m>>n;

C++
for (int i=1;i<=n;i++){

	cin>>x;
	if (w[x])	continue;
	ans++;
	h.push(x);
	w[x]=true;
	sum++;
	if (sum<=m)	continue;
	t=h.front();
	w[t]=false;
	h.pop();

}
cout<<ans;
return 0;

}

原文