uva 10763

原題

簡單題, 主要還是自定義一個類型裝兩個座標(因爲沒法創建那麼大的二維數組)

然後用map映射自定義類型來記錄是否有出現過,

再有就是用一個count計數器, 出現新的座標就+1, 匹配一對就-1, 以此來最後判斷是否全部匹配了

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring> 
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <deque> 
#include <map>
#include <cassert>
#include <iomanip>
#include <list>
using namespace std;
const int MAXN = 500000+10;
typedef long long LL;
typedef long long Type;
/*
uva 10763
關鍵 : map映射(記錄)自定義類型 
*/

struct Point{
	Type x;
	Type y;
	Point(const Type & a,const Type & b){ 
		x = a;
		y = b;
	}
	
};

bool operator<(const Point & a,const Point & b){
	if( a.x!=b.x ) return a.x<b.x;
	else return a.y<b.y;
}

int main(){
//	freopen("input2.txt","r",stdin);
	int n;
	map<Point,bool> mp;
	while( cin>>n && n>0 ){
		mp.clear();
		int notMatch = 0;
		Type a, b;
		while( n-- ){
			cin >> a >> b;
			Point p2(b,a);
			if( !mp[p2] ){
				Point p1(a,b);
				mp[p1] = true;
				notMatch++;
			}else{
				notMatch--;
			}
		}
		if( notMatch==0 ) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0; 
}


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