Codeforces 1008B - Turn the Rectangles
题目原址
[http://codeforces.com/contest/1008/problem/B]
题意
输入一个数 n,接下来 n 对数 , , 你可以交换其中的 和 使得数组 为广义单调递减。
题解
用另一变量储存 通过对 和 比较,选出符合广义单调递减的最大值作为新的 ,当不存在时,返回 NO 。
实现
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
int w,h;
int t=0;//储存上次的h
while(n--){
scanf("%d %d",&w,&h);
if(w > h)
w^=h^=w^=h; //交换wh,使得h>=w
if(t >= h || !t)//如果h小于等于上次的h,或者这是第一次
t = h;
else if(t >= w)
t = w;
else
return 0*printf("NO\n");
}
printf("YES\n");
return 0;
}