UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(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的更多相关文章
- uva 10763 Foreign Exchange(排序比较)
题目连接:10763 Foreign Exchange 题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败. 解题思 ...
- uva 10763 Foreign Exchange <"map" ,vector>
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...
- UVa 10763 Foreign Exchange(map)
Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...
- UVA 10763 Foreign Exchange
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Your non- ...
- uva:10763 - Foreign Exchange(排序)
题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...
- Foreign Exchange(交换生换位置)
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...
- 【UVA】10763 Foreign Exchange(map)
题目 题目 分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢. 代码 #include < ...
- [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange
题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...
- Foreign Exchange
10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...
随机推荐
- poj1236 Network of Schools【强连通分量(tarjan)缩点】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4316263.html ---by 墨染之樱花 [题目链接]http://poj.org/pr ...
- 五毛的cocos2d-x学习笔记01-创建项目
终于准备开始学习cocos2d-x了.因为想和同学一起做游戏参加比赛,所以打算学习很热的Cocos2d-x.因为已经学习了C++,所以我想入门应该不是很困难.再加上官网有中文教程以及多不胜数的游戏开发 ...
- PreTranslateMessage和TranslateMessage区别(转)
PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗口的消息都要通过这里,比较常用,当需要在MFC之前处理某些消息时,常常要在这里添加代码. ...
- json格式字符串与java.util.Map的互转(借助于jackson.jar)
package com.test.javaAPI.json; /** * json工具类 * * @author Wei * @time 2016年10月2日 下午4:25:25 */ public ...
- json在PHP中应用技巧
一.json_encode() 该函数主要用来将数组和对象,转换为json格式.先看一个数组转换的例子: $arr = array ('a'=>1,'b'=>2,'c'=>3,'d' ...
- ASP.NET jQuery 随笔 显示CheckBoxList成员选中的内容
通过jQuery来获取CheckBoxList成员内容. <%@ Page Language="C#" AutoEventWireup="true" Co ...
- maven安装jar到本地仓库
class12.jar这个东西在中央仓库里没有,所以,cmd到oracle\product\10.2.0\db_1\jdbc\lib路径下,mvn install 就好了(发布第三方jar到本地库) ...
- Android抖动动画
//CycleTimes动画重复的次数 public Animation shakeAnimation(int CycleTimes) { Animation translateAnimation = ...
- Fedora 17 安装 完全 指南
一.了解Fedora 17先来了解一下Fedora吧.它是由Red Hat赞助的一个全球性开源项目,秉承“自由”.“友爱”.“杰出”.“前卫”宗旨. 1.Fedora 17的主要系统改进内核:采用3. ...
- Uva 552 Prime Ring Problem(dfs)
题目链接:Uva 552 思路分析:时间限制为3s,数据较小,使用深度搜索查找所有的解. 代码如下: #include <iostream> #include <string.h&g ...