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

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

用stl做,map+pair。

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

代码:

 /*
* Author: illuz <iilluzen@gmail.com>
* 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;
}

UVA 10763 Foreign Exchange 出国交换 pair+map的更多相关文章

  1. uva 10763 Foreign Exchange(排序比较)

    题目连接:10763 Foreign Exchange 题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败. 解题思 ...

  2. uva 10763 Foreign Exchange <"map" ,vector>

    Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...

  3. UVa 10763 Foreign Exchange(map)

    Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...

  4. UVA 10763 Foreign Exchange

      Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description Your non- ...

  5. uva:10763 - Foreign Exchange(排序)

    题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...

  6. Foreign Exchange(交换生换位置)

     Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...

  7. 【UVA】10763 Foreign Exchange(map)

    题目 题目     分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢.     代码 #include < ...

  8. [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange

    题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...

  9. Foreign Exchange

     10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...

随机推荐

  1. php扩展类开发实例

    class Vector2D { private $_x; private $_y; /** * Constructor. */ public function __construct($x = 0, ...

  2. VC编程中如何设置对话框的背景颜色和静态文本颜色

    晚上编一个小程序,涉及到如何设置对话框的背景颜色和静态文本颜色.这在VC6.0中本来是一句话就搞定的事.在应用程序类中的InitInstance()函数添加: //设置对话框背景和文本颜色 SetDi ...

  3. BZOJ 1087 互不侵犯King (位运算)

    题解:首先,这道题可以用位运算来表示每一行的状态,同八皇后的搜索方法,然后对于限制条件不相互攻击,则只需将新加入的一行左右移动与上一行相&,若是0则互不攻击,方案可行.对于每种方案,则用递推来 ...

  4. hdu4370 0 or 1【最短路+建图】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4297627.html   ---by 墨染之樱花 题目链接:http://acm.hdu.ed ...

  5. authorization 元素(ASP.NET 设置架构)

    authorization 元素(ASP.NET 设置架构) 其他版本 1(共 1)对本文的评价是有帮助 - 评价此主题 [本文档仅供预览,在以后的发行版中可能会发生更改.包含的空白主题用作占位符.] ...

  6. Sass入门——基本特性-基础

    本文来自慕课网大漠 声明变量 三个部分:1.声明变量的符号"$"2.变量名称3.赋予变量的值 $brand-primary : darken(#428bca, 6.5%) !def ...

  7. Smarterer Test

    1.Using xp can swap two characters 2.In normal mode, use /abc/+4 can find the string "abc" ...

  8. Web开发找错基本思路

    WEB开发主要是两个交互(B/S数据) 浏览器:  1 包含html.css.js等客户端代码运行错误. 传输端: 1 路径引入错误,常用插件的引入(artDialog.Ztree.JQuery等). ...

  9. django template出错

    解决方法一: 先导入settings >>> from django.conf import settings >>> settings.configure() & ...

  10. Windows Phone 8初学者开发—第8部分:理解编译和部署

    原文 Windows Phone 8初学者开发—第8部分:理解编译和部署 第8部分:理解编译和部署 原文地址: http://channel9.msdn.com/Series/Windows-Phon ...