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 ...
随机推荐
- 网页压缩gzip的问题及说明教程
关于网页压缩gzip的问题及说明教程 最近比较多人反应gzip的问题 在wdcp的后台里已经有gzip功能的选项,也就是说,只要在这里开启了,就已支持 但从最近的问题中发现,基本上都是使用一些在线检测 ...
- uva311 - Packets(贪心)
题目:311 - Packets 题目大意:给出1*1, 2*2,3 *3, 4*4, 5*5, 6*6的箱子的个数,如今有若干个6*6的箱子,问最少用多少个箱子能够将给定的箱子都装进去. 解题思路: ...
- 让自己的apk可以被别人用二维码下载
通过二维码下载的流程是, 1.截获地址当有一个url被二维码扫描后的被截获,请先确认能够被截获. 2.接受intent无论是把这个消息的地址发送给activity,还是reciver,都要进入到你的程 ...
- 阿里Android一面(校招)
4.8号晚上8点多接到了阿里一面的电话,面试官人很好,和我聊了半个多小时.我面的是无线事业部,就是做淘宝客户端的那个部门.面试问的都很基础,刚开始问了hashmap和快速排序.接着就是问Android ...
- 关于RadUpload上传问题总结
最近在开发上传控件,使用RadUpload上传大附件 发现了几个小问题,总结后分享给大家: 1.IE6浏览器下文件的路径显示的是物理路径,需要进行转换 2.IIS7.0 配置时要选择经典模式 3.we ...
- [译]Stairway to Integration Services Level 13 - SSIS 变量回顾
介绍 在前一篇中我们组合了已经学过的事件冒泡 event bubbling, 日志记录 logging, 和父子模型 Parent-Child pattern 建立了自定义的SSIS包日志记录. 本文 ...
- C# Best Practices - Creating Good Methods
How to Define a Method Identify the problem => Define the single purpose => Specify the inputs ...
- 字符通向字节流的桥梁---- OutputStreamWriter
OutputStream out = System.out; OutputStreamWriter osw = new OutputStreamWriter(out); BufferedWriter ...
- python笔记之字符串
列表,元组,字符串的相互转换: 将字符串转换为序列和元组: >>> s="hello" >>> list(s)['h', 'e', 'l', ' ...
- jquery-1.10.2.min.js之Multiple markers at this line
1.windows-preferences 输入validation 2. 点击进入 3. 将JavaScript validator for js files 的两个对勾去了就OK! 4 ...