题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a)。

放在贪心这其实有点像检索。

用stl做,map+pair。

记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己出现的此时一样即可。

代码:

 /*
* Author: illuz <[email protected]>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10763.cpp
* Lauguage: C/C++
* Create Date: 2013-08-25 09:47:55
* Descripton: UVA 10763 Foreign Exchange, map
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL; /****** TEMPLATE ENDS ******/ const int MAXN = 500100;
struct Pair {
int x, y;
Pair(int a, int b) : x(a), y(b) {}
friend bool operator < (const Pair& a, const Pair& b) {
return (a.x < b.x || (a.x == b.x && a.y < b.y));
}
};
map<Pair, int> m;
int n, a, b; int main() {
while (scanf("%d", &n) && n) {
m.clear();
rep(i, n) {
scanf("%d%d", &a, &b);
m[Pair(a, b)]++;
}
bool flag = true;
FI(i, m) {
if (i->second != m[Pair(i->first.y, i->first.x)]) {
flag = false;
// break;
}
}
if (flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
04-30 12:01