题目连接: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(排序比较)的更多相关文章

  1. UVA 10763 Foreign Exchange 出国交换 pair+map

    题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...

  2. uva 10763 Foreign Exchange <"map" ,vector>

    Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...

  3. UVA 10763 Foreign Exchange

      Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description Your non- ...

  4. UVa 10763 Foreign Exchange(map)

    Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...

  5. uva:10763 - Foreign Exchange(排序)

    题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...

  6. 【UVA】10763 Foreign Exchange(map)

    题目 题目     分析 没什么好说的,字符串拼接一下再放进map.其实可以直接开俩数组排序后对比一下,但是我还是想熟悉熟悉map用法. 呃400ms,有点慢.     代码 #include < ...

  7. Foreign Exchange

     10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...

  8. UVA Foreign Exchange

    Foreign Exchange Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Your non ...

  9. Foreign Exchange(交换生换位置)

     Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...

随机推荐

  1. xtrabackup执行备份要拥有的权限

    xtrabackup备份的原理: xtrabackup直接复制datadir目录中的文件到备份目录下.这样问题就来了,在备份的时候mysql可以还在执行写入操作:所以xtrabackup会不停的去扫描 ...

  2. Combotree,datebox 启用 禁用

    combotree <input type="checkbox" id="ckMonitor"></input> <input i ...

  3. WPF:构建应用程序

    原文 http://www.cnblogs.com/free722/archive/2011/11/13/2247455.html WPF相关的项目内容包含在App.Xaml和Window1.xaml ...

  4. JS获取年月日时分秒

    var d = new Date(); ) + "-" + d.getDate() + " " + d.getHours() + ":" + ...

  5. display的table和cell外加table-layout:fixed等分布局,外加换行,word-wrap:break-word

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. S3C6410嵌入式应用平台构建(五)——linux-3.14.4移植到OK6410-(Nand分区问题)

    前一篇文章,我们的Linux能后启动了,只是在识别nand时候,没有获取到时钟源,导致后面的分区没哟进行. 我们从启动的log发现: [06/08-11:25:41:371]s3c24xx-nand ...

  7. lighttpd配置虚拟主机/php等WEB环境

    lighttpd(1.4.37)配置如下 server.document-root = "/var/www/lighttpd/" server.port = 8888 server ...

  8. 简单的Session登录

    Login前台页面 <form id="form1" action ="" method="post"> <input t ...

  9. HTML不常用元素:optgroup

    在网页表单中,<optgroup>元素用于在<select>元素中创建一组选项<option>.这个可以更好的区分每一个组选项之间的区别. 这个元素包含两个属性:d ...

  10. 解决URL请求中的中文乱码问题

    解决URL提交中文出现乱码有两种办法:1.请求端的中字符有encodeURI进行一次转码,如: var url="/getUser?name="+encodeURI(name);服 ...