社区讨论

I need help!

P1540[NOIP 2010 提高组] 机器翻译参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@lz2q0368
此快照首次捕获于
2024/07/26 21:10
2 年前
此快照最后确认于
2024/07/26 23:04
2 年前
查看原帖

10分求调

C
#include <bits/stdc++.h>

using namespace std;

int n, m;
int a[1000000];
queue<int> q;
queue<int> q1;
int ans;

int main(){
	cin >> n >> m;
	for (int i = 1; i <= m; i++){
		cin >> a[i];
	}
//	cout << q.size() << endl;
	for (int i = 1; i <= m; i++){		
		if (q.size() == 0){
			q.push(a[i]);
			ans++;
//			cout << a[i] << endl;
		}
		else{
			int sum = 0;
			for (int j = 1; j <= q.size(); j++){
				if (a[i] == q.front()) break;
				else{
					q1.push(q.front());
					q.pop();
					sum++;
				}
			}
			for (int j = 1;j <= q1.size(); j++){
				q.push(q1.front());
				q1.pop();
			}
			if (sum == q.size()){
				if (q.size() == n){
					q.pop();
					q.push(a[i]);
					ans++;
				}
				else if (q.size() < n){
					q.push(a[i]);
					ans++;
				}
			}
		}	
	}
	cout << ans << endl;
	return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...