暑期集训2:ACM基础算法 练习题B:CF-1008B
2018学校暑期集训第二天——ACM基础算法
练习题B —— CodeForces - 1008B
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≤n≤1051≤n≤105) — the number of rectangles.
Each of the next nn lines contains two integers wiwi and hihi (1≤wi,hi≤1091≤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).
Examples
Input
3 3 4 4 6 3 5
Output
YES
Input
2 3 4 5 5
Output
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.
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;struct Point{int a,b;
}t[100010];int main(void)
{int n;scanf("%d", &n);for(int i=0;i<n;i++)cin >> t[i].a >> t[i].b;int maxn=max(t[0].a,t[0].b);int jua,jui;bool judge=1;for(int i=1;i<n;i++){jua=max(t[i].a,t[i].b);if(jua<=maxn){maxn=jua;}else{jui=min(t[i].a,t[i].b);if(jui<=maxn){maxn=jui;}else{judge=0;break;}}}if(judge)cout << "YES";elsecout << "NO";return 0;
}
暑期集训2:ACM基础算法 练习题B:CF-1008B相关推荐
- 暑期集训2:ACM基础算法 练习题G:POJ - 1298
2018学校暑期集训第二天--ACM基础算法 练习题G -- POJ - 1298 The Hardest Problem Ever Julius Caesar lived in a time o ...
- 暑期集训2:ACM基础算法 练习题C:CF-1008A
2018学校暑期集训第二天--ACM基础算法 练习题A -- CodeForces - 1008A Romaji Vitya has just started learning Berlanes ...
- 暑期集训2:ACM基础算法 练习题A:CF-1008C
2018学校暑期集训第二天--ACM基础算法 练习题A -- CodeForces - 1008C Reorder the Array You are given an array of inte ...
- 暑期集训2:ACM基础算法 例2:POJ-2456
2018学校暑期集训第二天--ACM基础算法 例二 -- POJ - 2456 Aggressive cows Farmer John has built a new long barn, wi ...
- 暑期集训2:ACM基础算法 例1:POJ-1064
2018学校暑期集训第二天--ACM基础算法 例一 -- POJ - 1064 Cable master Inhabitants of the Wonderland have decided to ...
- ACM基础算法入门及题目列表
对于刚进入大学的计算机类同学来说,算法与程序设计竞赛算是不错的选择,因为我们每天都在解决问题,锻炼着解决问题的能力. 这里以TZOJ题目为例,如果为其他平台题目我会标注出来,同时我的主页也欢迎大家去访 ...
- NOIP训练营集训笔记—信息学基础算法(倍增与分治算法
本文摘自清北OI学堂内部笔记,作者潘恺璠,来自柳铁一中曾参加过清北训练营提高组精英班,主要记录的是信息学基础算法.笔记非常详细,特分享给大家! NOIP2019年夏令营正在报名中,6大校区10种班 ...
- CDU集训代码:基础算法和数据结构2
做题地址: http://acm.hdu.edu.cn/diy/contest_login.php?cid=16636 Problem A: HDU1040 排序题,可以直接使用c++提供的排序,如果 ...
- 详解ACM基础算法—DFS深度优先搜索算法 HIT杨朔
深度优先搜索(DFS)是搜索手段之一.是从某个状态开始不断转移状态直到无法转移为止,然后退回到前一步状态继续转移其他状态,可以想象为一个沿树爬行的虫子,在一个交叉口他会首先随机选择一条分岔路口一直走下 ...
最新文章
- CommonJs, AMD/RequireJs,CMD/seajs
- 数据结构(算法)-线性表2(单链表)
- mysql存储过程是什么
- 跨平台APP JQuery Mobile开发-张晨光-专题视频课程
- 为WPF播放GIF伤神不?
- 通过外部文件覆盖打包的Spring应用程序属性文件
- .NET 二维码生成(ThoughtWorks.QRCode)
- cython加密代码python_利用Cython对python代码进行加密
- 技术圈的女性工程师都去哪呢?
- 浏览器输入网址到页面呈现的过程
- java学习笔记(3.31)
- windows7系统如何实现AirPrint打印
- matlab安装mosek工具包
- excel提取身份证出生日期_Excel如何从身份证号码中提取年龄
- XMLHttpRequest请求跨域问题解决方案
- 添加视频字幕后期制作Premiere Pro 2022中文
- 新手蓝牙耳机选购攻略,2021什么牌子蓝牙耳机不容易踩雷
- 电脑WiFi图标不见了?!怎么办......≡ (▔﹏▔) ≡
- iOS - UILabel点击选中文字,部分高亮,YYLabel
- 内网架设FTP服务器(serv-u)