题意:给出很多对数字,看看每一对(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. Baby Step Gaint Step

    给定同余式,求它在内的所有解,其中总是素数. 分析:解本同余式的步骤如下 (1)求模的一个原根 (2)利用Baby Step Giant Step求出一个,使得,因为为素数,所以有唯一解. (3)设, ...

  2. 在 Linux RedHatEL6 环境下安装配置 JDK1.7 + Tomcat7.0 + MySQL5.6

    RedHatEL6 JDK安装路径: /usr/java/jdk1.7 Tomcat安装路径:/usr/local/tomcat7/ MySQL安装路径: /usr/local/mysql 总共分为以 ...

  3. UIControl IOS控件编程 及UITextField的讲解

    第一部分 UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件.UIPageCo ...

  4. Webstorm入门-----常用快捷键

    为了提高敲代码的速度.我们所需要关注的各种快捷键: 首先,快捷键的设置                  相关连接: http://www.cnblogs.com/dc10101/archive/20 ...

  5. 前端CSS规范大全

    一.文件规范 1.文件均归档至约定的目录中(具体要求以豆瓣的CSS规范为例进行讲解): 所有的CSS分为两大类:通用类和业务类.通用的CSS文件,放在如下目录中: 基本样式库 /css/core 通用 ...

  6. D - D 田忌赛马

    D - D    田忌赛马   解题报告 hdu 1052 Tian Ji -- The Horse Racing 链接:http://acm.hust.edu.cn/vjudge/contest/v ...

  7. 字符串匹配算法(KMP)

    字符串匹配运用很广泛,举个简单例子,我们每天登QQ时输入账号和密码,大家有没有想过账号和密码是怎样匹配的呢?登录需要多长时间和匹配算法的效率有直接的关系. 首先理解一下前缀和后缀的概念: 给出一个问题 ...

  8. NOIP2015酱油记

    day0 坐动车到广州..下午就在酒店颓... day1 早上6:30起床...大概8:00到六中..ZSJZ众貌似很晚才到..毕竟他们酒店就在学校门口(真的就刚刚好是门口...),大概8:15进去机 ...

  9. 控制台console使用MFC库函数,Cout输出CString的方法

    新建工程的时候选择:Win32 Console Application 在向导的地方勾选MFC头文件支持,确认即可 等待初始化文件完成后,VS2010会自动打开 项目名.cpp的文件 其中int _t ...

  10. 重新生成IE02

    procedure ReBuild_IE02( pi_aac001 in number, po_fhz out varchar2, po_msg out varchar2) is type typ_t ...