题目连接: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. 动态Script标签 解决跨域问题

     动态Script 解决跨域问题 1.动态创建scriptcreateScript : function(src){ var varScript = document.createElement(&q ...

  2. echarts实现上海地域PM值(map、timeline)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. windows命令行模式下无法打开python程序解决方法

    今天刚开始学Python,首先编写一个简单地hello world程序,想在命令行模式运行,结果出现下面: 经过一番思考,发现用cd命令可以解决这件事,看下图: 这样就解决了.

  4. OpenCV学习 1:OpenCV安装与第一个图像显示程序

    原创作品,转载请注明出处 为了提升逼格,决定学下OpenCV,想想如果可以做人脸识别,定点降落,让飞机跟着自己飞..想想都有点小激动.这只是想的,能不能学会还不知道..哈..      1:先下载:h ...

  5. Oracle提示“资源正忙,需指定nowait”的解决方案

    Oracle提示“资源正忙,需指定nowait”的解决方案  | T 本文我们主要介绍了Oracle数据库操作表时提示“资源正忙,需指定nowait”的解决方案,希望能够对您有所帮助. AD:51CT ...

  6. Cortex-M3学习日志(四) -- UART0实验

    LPC1768含有4 个符合16C550工业标准的异步串口UATR0-UART3,其中UART1具有标准的MODEM接口和RS-485/EIA-485接口模式.串口通讯接口是连接计算机.终端.通讯控制 ...

  7. ultravnc

    virsh attach-disk

  8. 用sqlserver处理excel表格

    本来最近在研究微信公众平台的,老大临时交我个任务,把excel表格里的数据导入sql数据库,我想这so easy嘛. 没想都在上面消磨了两天... 把情况介绍下:在数据库中有如下这样结构的表(A表) ...

  9. S3C2416裸机开发系列十六_sd卡驱动实现

    S3C2416裸机开发系列十六 sd卡驱动实现 象棋小子    1048272975 SD卡(Secure Digital Memory Card)具有体积小.容量大.传输数据快.可插拔.安全性好等长 ...

  10. MFC数据类型(data types)

    为便于理解MFC库函数中的各种形参,现将MFC中常见的参数类型总结如下: 下面这些是和Win32程序(SDK程序)共同使用的数据类型: 数据类型 意义 BOOL Boolean值(布尔值,不是TRUE ...