14147: 【原4147】翻转长方形

题目描述

author: Yifan 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4147

Sample1 Input

``````3
3 4
4 6
3 5
``````

Sample1 Output

``````YES
``````

Sample2 Input

``````2
3 4
5 5
``````

Sample2 Output

``````NO
``````

BugenZhao's solution

``````//
// Created by BugenZhao on 2019/3/16.
//
// 娱乐

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
int n;
int w, h;
int max;
int currHeight = 0x7fffffff;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> w >> h;
if (w > h) {
swap(w, h);
}
if (currHeight < w) {
cout << "NO" << endl;
return 0;
} else if (currHeight < h) {
currHeight = w;
} else {
currHeight = h;
}
}
cout << "YES" << endl;
return 0;
}
``````

ligongzzz's solution

``````#include "iostream"
#include "cstdio"
using namespace std;

constexpr int inf = (int)(1e9 + 7);

int main() {
int n;
scanf("%d", &n);

for (int i = 0, last = inf; i < n; ++i) {
int wi, hi;
scanf("%d %d", &wi, &hi);
if (wi <= last && hi <= last) {
last = wi > hi ? wi : hi;
}
else if (wi <= last) {
last = wi;
}
else if (hi <= last) {
last = hi;
}
else {
cout << "NO";
return 0;
}
}
cout << "YES";

return 0;
}
``````

skyzh's solution

``````#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;

int main() {
int n, wi, hi;
int c_H = INT_MAX;
scanf("%d", &n);
bool ok = true;
for (int i = 0; i < n; i++) {
scanf("%d%d", &wi, &hi);
int c_min = min(wi, hi);
int c_max = max(wi, hi);
if (c_min > c_H) {
ok = false;
} else {
if (c_max <= c_H) c_H = c_max;
else c_H = c_min;
}
}
if (ok) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
``````