题目连接: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. js 报错 :object is not a function

    object is not a function 我遇到的具体问题是:js命名方法重复了,找到了别的地方,改个方法名就可以了 var h2_price = document.getElementByI ...

  2. ASP.NET页面跳转

    总结一下跳转方式: <a>标签 <a href=”home.aspx”></a> HyperLink控件 Asp.net 服务器端控件 属性NavigateUrl指 ...

  3. Linux----函数中变量的作用域、local关键字。

    问题引出: 问题说明: shell的函数中如果变量的前面没有加local关键字.在全局作用域内存在这个变量名的情况下.函数中会直接使用这个变量 而不是自己创建一个.要想做到在函数创建一个变量也是可以的 ...

  4. poj 3273 Monthly Expense (二分搜索,最小化最大值)

    题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...

  5. 《Linux 设备驱动程序》读后感。 并发,竞态,死锁。

    1. 概念 并发:在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行. 来源: 1. Linux ...

  6. Python的迭代器(iterator)和生成器(constructor)

    一.迭代器(iterator) 1.迭代器的概述 在Python中,for循环可以用于Python中的任何类型,包括列表.元祖等等,实际上,for循环可用于任何“可迭代对象”,这其实就是迭代器 迭代器 ...

  7. 达内TTS6.0课件oop_day05

  8. inotify

    inotify,文件系统控制函数,通知机制: ioctl, io控制函数

  9. SQL Server 使用ROW_NUMBER()进行分页

    代码示例: WITH domain AS(SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) ids,* FROM dbo.DomainInfo) SELECT * ...

  10. win7+cygwin+hadoop+eclipse

    1.Cygwin : Net    下的:openssh,openssl Base  下的:sed (若需要Eclipse,必须sed)默认即可 Devel 下的:subversion(建议安装) 2 ...