uva 10763 Foreign Exchange(排序比较)
题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败。
解题思路:
给出数据 10
x y
1 2
2 1
3 4
4 3
100 200
200 100
57 2
2 57
1 2
2 1
按照排序:
xy y x
12 1 2
12 1 2
21 2 1
21 2 1
257 2 57
34 3 4
43 4 3
572 57 2
100 200 100 200
200 100 200 100
如果两个序列相同的话,说明交换成功,因为对应x = 1 , y = 2时,按照x, y 的大小排序,这对数字应该放在第一位,如果存在x = 2, y = 1,按照y,x的大小排序,也应该放在第一位。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 500005; struct que {
int x;
int y;
}tmp[N], rec[N]; bool cmp(const que &a, const que &b) {
if(a.x < b.x)
return true;
else if (a.x > b.x)
return false;
else if (a.y < b.y)
return true;
else
return false;
} int main() {
int n;
while (scanf("%d", &n), n) {
// Init;
memset(tmp, 0, sizeof(tmp));
memset(rec, 0, sizeof(rec)); // Read;
for (int i = 0; i < n; i++) {
scanf("%d%d", &tmp[i].x, &tmp[i].y);
rec[i].y = tmp[i].x;
rec[i].x = tmp[i].y;
} sort(tmp, tmp + n, cmp);
sort(rec, rec + n, cmp); int flag = 1;
for (int i = 0; i < n; i++)
if (tmp[i].x != rec[i].x || tmp[i].y != rec[i].y) {
flag = 0;
break;
}
printf("%s\n", flag ? "YES" : "NO");
}
return 0;
}
uva 10763 Foreign Exchange(排序比较)的更多相关文章
- UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...
- uva 10763 Foreign Exchange <"map" ,vector>
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...
- UVA 10763 Foreign Exchange
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Your non- ...
- UVa 10763 Foreign Exchange(map)
Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...
- uva:10763 - Foreign Exchange(排序)
题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...
- 【UVA】10763 Foreign Exchange(map)
题目 题目 分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢. 代码 #include < ...
- Foreign Exchange
10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...
- UVA Foreign Exchange
Foreign Exchange Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Your non ...
- Foreign Exchange(交换生换位置)
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...
随机推荐
- [转载]node.js express 4.x 安装指南,没有自动配置环境变量的问题
前几天express 推出了4.0,得知这个消息,自己尝试了一下,突然发现用以前的文档上的操作出现了各种问题.结果只能去看文档,现在在这个给大家分享下4.0版本的安装. 先说下如果需要用express ...
- PHP fopen和fwrite函数实现创建html页面
思路 用fopen函数和fread函数得到模板,然后用str_replace函数替换模板标签为变量,最后用fwrite函数输出新的HTML页面 index.html模板页面 <!DOCTYPE ...
- [LeetCode]题解(python):154-Find Minimum in Rotated Sorted Array II
题目来源: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 题意分析: 给定一个有重复的翻转的数组,找到最 ...
- linux实用指令---持续更新
awk '!a[$0]++' a > b 删除重复行 ldd 判断某条命令需要哪些共享库文件的支持 --------------- ]$ ldd a.out ...
- cad2007 钢筋符号显示为问号
如题:cad2007 钢筋符号显示为问号 解决办法:下载Tssdeng,解压(Tssdeng.rar) 把下载到的cad大字体Tssdeng.shx文件放到autoCAD2007安装目录C:\Prog ...
- poj1665
#include <stdio.h> #include <stdlib.h> #define pi 3.1415926 int main() { float dia,tim; ...
- 利用UIScrollView和UIPageControl实现多页图片欢迎页面
在.h文件当中实现UIScrollViewDelegate协议,让控制器充当代理: #import <UIKit/UIKit.h> @interface RPRootViewControl ...
- _视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- css中的media
说起CSS3的新特性,就不得不提到 Media Queries .最近 Max Design 更新的一个泛读列表里,赫然就有关于 Media Queries 的文章.同时位列其中的也有前天我刚刚翻译的 ...
- 交换机access和trunk的一些小结(转)
以太网端口有 3种链路类型:access.trunk.hybird Access类型端口只能属于1个VLAN 般用于连接计算机 端口: Trunk类型端口可以允许多个VLAN通过,可以接收和发送多个 ...