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 ...
随机推荐
- 一个SysLog实现
http://www.ice.com/java/syslog/index.shtml http://alvinalexander.com/servlets
- openNebulafrontEnd ComputeNode 配置记录
1,OpenNebula nfs(file system shared) for image datastore;
- 修改ubuntu的默认python版本
ubuntu14.04LTS上装有两个版本的python:python2.7.6与python3.4,默认使用python2.7.6. 可以使用以下命令来修改默认python版本: sudo cp / ...
- SPOJ QTREE4 lct
题目链接 这个题已经处于花式tle了,改版后的spoj更慢了.. tle的话就多交几把... #include <iostream> #include <fstream> #i ...
- C++ - Vector 计算 均值(mean) 和 方差(variance)
Vector 计算 均值(mean) 和 方差(variance) 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24623187 ...
- T-SQL 查询语句总结
我们使用一下两张表作为范例: select * from [dbo].[employee] select * from [dbo].[dept] 1.select语句 DISTINCT:去掉记录中的重 ...
- 20141014C#面向对象抽象方法,抽象类,接口
里氏代换原则.可以用子类的对象替代父类的对象. 抽象依赖原则.依赖——形参,关联 一.抽象方法: 在一些父类中,某些行为不是非常明确,因此无法用代码来具体实现,但是类必须具备此方法,因此把这样的方法定 ...
- 官网下载旧版本的Xcode
1.登录“苹果开发者中心”——>“SDKs” 2.点击“Xcode” 3.点击页面顶部的“Download” 4.点击页面左下方的“additional tools”,这样就可以查询到各个Xco ...
- php用百度地图API进行IP定位和GPS定位
<?php /** * 根据地理坐标获取国家.省份.城市,及周边数据类(利用百度Geocoding API实现) * 百度密钥获取方法:http://lbsyun.baidu.com/apico ...
- 标准模板库——IO库
IO库设施: . istream(输入流)类型,提供输入操作. . ostream(输出流)类型,提供输出操作. . cin,一个istream对象,从标准输入读取数据. . cout,一个ostre ...