1

root 站长 2024-07-11 16:05:06 19

【金山文档 | WPS云文档】 张涵宇测试题 https://kdocs.cn/l/cvIJRngyc6NE

{{ vote && vote.total.up }}

共 2 条回复

ykj34 老六
#include<bits/stdc++.h>
using namespace std;
int a[1010];
int b[1010];
int main(){
	int n,m,k;
	int wz,cnt;
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++){
		for(int ii=1;ii<=1000;ii++)a[ii]=b[ii]=0;
		wz=1;cnt=1;
		for(int j=1;j<=n;j++){
			cin>>a[j];
		}
		int j=1,bj=0;
		while(j<=n){
			cout<<wz<<" "<<j<<" "<<cnt<<" "<<b[cnt-1]<<endl;
			if(cnt>m){
				cout<<"NO2"<<j<<endl;
				bj=1;
				break;
			}
			if(b[cnt-1]==wz){
					cnt--;
					wz++;
					continue;
				}
			
			if(a[j]==wz){
				wz++;
				j++;
				
				continue;
			}
			if(a[j]>wz){
				b[cnt++]=a[j];
				j++;
				continue;
			}
			if(b[cnt-1]!=wz){
					cout<<"NO1"<<wz<<endl;
					bj=1;
					break;
				} 
				
				
			
			
			
		}
		if(bj==0 && cnt<=1)cout<<"YES"<<endl;
		else if(bj==0 && cnt>=2)cout<<"No1"<<" "<<cnt<<endl;
	}
	
	
	
	
	return 0;
} 
root 站长
#include <bits/stdc++.h>   //导入输入输出流

using namespace std;  //使用标准命名空间

int main() 
{
	int n, m, k;
	cin >> n >> m >> k;	
	while (k -- )
	{
		stack<int> s;
		int a[1010];
		for (int i = 1; i <= n; i ++ ) 
			cin >> a[i];
		int ok = 1;
		for (int i = 1, j = 1; i <= n; i ++ )
		{
			if (a[i] == j)
			{
				j++;
				while (!s.empty() && s.top() == j)
				{
					s.pop();
					j++;
				}
			}
			else
			{
				while (!s.empty() && s.top() == j)
				{
					s.pop();
					j++;
				}
				s.push(a[i]);
				if (s.size() > m)
				{
					ok = 0;
					break;
				}
			}
		} 
		if (!ok || !s.empty()) puts("NO");
		else puts("YES");
	}
	return 0;
}