算法競賽入門經典(第二版)-劉汝佳-第五章 交流生




#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
struct node
{
	int a,b;
	node(int x,int y){a=x,b=y;}
	bool operator < (const node &n) const
	{
		if(n.a!=a)   return n.a<a;
		return n.b<b;
	}
};
int main()
{
//	freopen("1.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int n;
	while(scanf("%d",&n),n)
	{
		map<node,int> m;
		int i,j;
		for(i=0;i<n;i++)
		{
			int a,b;
			scanf("%d%d",&a,&b);
			node x(a,b);
			m[x]++;
			j++;
		}
		map<node,int>::iterator it;
		for(it=m.begin();it!=m.end();it++)
		{
			node x=it->first;
			swap(x.a,x.b);
			if( it->second!=m[x] ) break;
		}
		if(it==m.end()) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}




ps

1.結構體所有元素都要排序。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章