麻了,把这讨论区所有出现的例子都试了一下,都能过,就是提交过不了
查看原帖
麻了,把这讨论区所有出现的例子都试了一下,都能过,就是提交过不了
268811
画船听雨楼主2022/1/13 19:55
#include<iostream>
#include<stack>
#include<queue>
using namespace std;

int main() {
	int q, n, i, j,temp,temp1,temp2,temp3,sum,con,max=0,flag=0,acc=0;
	stack<int> a,c;
	queue<int> b;
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> n;
		sum = 0;
		for (j = 0; j < n; j++) {
			cin >> temp;
			a.push(temp);
			if (temp > max)
				max = temp;
			
		}
		for (j = 0; j < n; j++) {
			cin >> temp1;		
			b.push(temp1);

		}
		con = b.size();
		while (!b.empty()) {
			temp2 = b.front();
			temp3 = a.top();
			if (temp2 == max) {//如果出现最大值了,就说明出栈序列之后都不能存在逆序输出的。比如1 2 3 4 5和1 2 5 3 4。5出现之后记录下来,然后它后面的3和5隔了一个4,这样就不可行了。
					flag = 1;
				}
			if (temp2 != temp3) {
				c.push(a.top());
				a.pop();
				if (flag == 1) {
					acc++;
					if (c.size() > 0) {
						cout << "No" << endl;
						while (!a.empty()) {
							a.pop();
						}
						while (!b.empty()) {
							b.pop();
						}
						while (!c.empty()) {
							c.pop();
						}
						break;
					}
				}
				
			}
			else {

				b.pop();
				a.pop();

				while (!c.empty()) {/*把c
 中所有的元素放到a里面*/
					a.push(c.top());
					c.pop();
				}
			}
			//sum++;
			//if (sum >= (con+1)*n/2) {
			//	cout << "No" << endl;
			//	break;
			//}
		if (b.size() == 0)
			cout << "Yes" << endl;
		}

	}
	return 0;
}
2022/1/13 19:55
加载中...