求助P1540 [NOIP2010 提高组] 机器翻译
  • 板块学术版
  • 楼主0QAQ0
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/9/27 10:20
  • 上次更新2024/9/27 13:59:34
查看原帖
求助P1540 [NOIP2010 提高组] 机器翻译
538798
0QAQ0楼主2024/9/27 10:20

这个代码80分,我检查好几遍就是找不出问题,求助大佬! 哪有问题帮我指出来下,谢谢!

#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int m,n;
int x;
int tot;
int a[1010];
inline int read()
{
	register int x=0,y=1;
	register char c=getchar();
	while (c<'0'||c>'9')
	{
		if (c=='-')
		{
			y=-1;
		}
		c=getchar();
	}
	while (c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*y;
}
int main()
{
	m=read();
	n=read();
	for (int i=1;i<=n;i++)
	{
		x=read();
		int t=q.size();
		if (a[x]==0)
		{
			a[x]=x;
		}
		else if (a[x]!=0) continue;
		if (t>=0&&t<m)
		{
			q.push(x);
			tot++;
		}
		else
		{
			a[q.front()]=0;
			q.pop();
			q.push(x);
			tot++;
		}
	}
	cout<<tot;
	return 0;
}
2024/9/27 10:20
加载中...