#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main()
{
int ;
scanf(“%d”,&);
while (_–)
{
int n;
scanf(“%d”,&n);
stackst;
int mxxxx=-1;
for (int i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
mxxxx=max(mxxxx,a[i]);
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
}
else
{
st.push(a[i]);
}
}
if (st.size()<=1)
{
if (!st.empty()&&st.top()!=mxxxx)
{
printf(“nO\n”);
continue;
}
int fff=1;
if (!st.empty()) st.pop();
int tmp=-1;
for (int i=1;i<=n;i++)
{
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
if (st.empty())
{
tmp=-1;
}
}
else
{
st.push(a[i]);
if (tmp==-1)
{
tmp=a[i];
continue;
}
if (a[i]>tmp)
{
fff=0;
break;
}
tmp=a[i];
}
}
if (fff) printf(“YES\n”);
else printf(“nO\n”);
}
else
{
printf(“nO\n”);
}
}
return 0;
}
您可以套上代码框吗
int i=1;
就像这样
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main()
{
int _;
scanf("%d",&_);
while (_--)
{
int n;
scanf("%d",&n);
stack<int>st;
int mxxxx=-1;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
mxxxx=max(mxxxx,a[i]);
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
}
else
{
st.push(a[i]);
}
}
if (st.size()<=1)
{
if (!st.empty()&&st.top()!=mxxxx)
{
printf("nO\n");
continue;
}
int fff=1;
if (!st.empty()) st.pop();
int tmp=-1;
for (int i=1;i<=n;i++)
{
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
if (st.empty())
{
tmp=-1;
}
}
else
{
st.push(a[i]);
if (tmp==-1)
{
tmp=a[i];
continue;
}
if (a[i]>tmp)
{
fff=0;
break;
}
tmp=a[i];
}
}
if (fff) printf("YES\n");
else printf("nO\n");
}
else
{
printf("nO\n");
}
}
return 0;
}
你干嘛哈哈有,你集合用栈啊
3 个赞
你这打的也不对啊
3 个赞