标签:while .com can pac http ima continue printf include
就是括号匹配的题目,如果有交集就是NO
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<stack>
#include<algorithm>
using namespace std;
stack<int> s;
int a[200005];
int main()
{
int t,n,m,temp1,temp2,i;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
memset(a,0,sizeof (a));
while(!s.empty()) s.pop();
for(i=1;i<=m;i++)
{
scanf("%d%d",&temp1,&temp2);
a[temp1]=i;a[temp2]=i;
}
for(i=1;i<=2*n;i++)
{
if(a[i]==0) continue;
if(s.empty()) s.push(a[i]);
else
{
if(a[i]==s.top()) s.pop();
else s.push(a[i]);
}
}
if(s.empty()) printf("YES\n");
else printf("NO\n");
}
}
标签:while .com can pac http ima continue printf include
原文地址:https://www.cnblogs.com/wzl19981116/p/10087456.html