• A - Turn the Rectangles


    There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

    Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

    Input

    The first line contains a single integer nn (1 \leq n \leq 10^51≤n≤105) — the number of rectangles.

    Each of the next nn lines contains two integers w_iwi​ and h_ihi​ (1 \leq w_i, h_i \leq 10^91≤wi​,hi​≤109) — the width and the height of the ii-th rectangle.

    Output

    Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

    You can print each letter in any case (upper or lower).

    Sample 1

    InputcopyOutputcopy
    3
    3 4
    4 6
    3 5
    
    YES
    

    Sample 2

    InputcopyOutputcopy
    2
    3 4
    5 5
    
    NO
    

    Note

    In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

    In the second test, there is no way the second rectangle will be not higher than the first one.

     

    1. #include <iostream>
    2. #include <iomanip>
    3. #include <cstdio>
    4. #include <cmath>
    5. #include <string.h>
    6. #include <climits>
    7. #include <map>
    8. typedef long long ll;
    9. using namespace std;
    10. const double eps = 1e-7;
    11. map<int, pair<int,int>> mm;
    12. int n;
    13. int main()
    14. {
    15. cin >> n;
    16. for (int i = 1; i <= n; i++)
    17. {
    18. int num1, num2;
    19. cin >> num1 >> num2;
    20. mm[i] = make_pair(num1, num2);
    21. }
    22. int maxbian = max(mm[1].first, mm[1].second);
    23. for (int i = 2; i <= n; i++)
    24. {
    25. if (mm[i].first > maxbian && mm[i].second > maxbian)
    26. {
    27. cout << "NO" << endl;
    28. return 0;
    29. }
    30. else if (mm[i].first > maxbian) maxbian = mm[i].second;
    31. else if (mm[i].second > maxbian) maxbian = mm[i].first;
    32. else maxbian = max(mm[i].first, mm[i].second);
    33. }
    34. cout << "YES" << endl;
    35. return 0;
    36. }

     

  • 相关阅读:
    Elixir学习笔记——输入输出和文件系统
    webpack知识点整理
    android studio 找不到设备
    Contact mechanics 分析
    DC电源模块高低温试验的重要性
    Golang 中的字符串:常见错误和最佳实践
    Redis源码解析-通信协议
    经典算法题12-贪心算法
    【AcWing14】【LeetCode】KMP算法-28/796/214/459
    基于springboot的医护人员排班系统 全套代码 全套文档
  • 原文地址:https://blog.csdn.net/GF0919/article/details/132754851