output

standard output

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

Copy
3
3 4
4 6
3 5
output

Copy
YES
input

Copy
2
3 4
5 5
output

Copy
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.

题意:这里有n个矩形,你可以让每个矩形旋转90度,可以旋转多次或者不旋转,但是你不能改变矩形的排列顺序,每一个矩形不能比它前一个矩形高,如果可以输出YES,否则输出NO。

分析:使第一个矩形的高最大,如果下一个矩形的宽和高的最小值小于它前一个矩形的高,比较:1,(1)如果宽大于前一个的高,则把该矩形的高作为高(2)如果高大于前一个矩形的高,则把该矩形的宽作为该矩形的高(3)如果宽和高均小于前一个的高,则找出宽和高较大的那个作为该矩形的高   2,如果该矩形的宽高最小值大于前一个矩形的高,那么直接输出NO

 #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,w[],h[];
while(~scanf("%d",&n))
{
for(int i=; i<=n; i++)
{
scanf("%d %d",&w[i],&h[i]);
}
int t1,t2,i;
for(i=; i<=n; i++)
{
if(i==)
t1=max(w[i],h[i]);
else
{
t2=min(w[i],h[i]);
if(t2<=t1)
{
if(w[i]>t1)
t1=h[i];
else if(h[i]>t1)
t1=w[i];
else if(w[i]<=t1&&h[i]<=t1)
t1=max(w[i],h[i]);
}
else
{
break;
}
} }
if(i==n+)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
 

Turn the Rectangles 1008B的更多相关文章

  1. CF 1008B Turn the Rectangles(水题+贪心)

    There are n rectangles in a row. You can either turn each rectangle by 90 degrees or leave it as it ...

  2. Codeforces Round #497 (Div. 2)B. Turn the Rectangles

    Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...

  3. 2018SDIBT_国庆个人第一场

    A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...

  4. CF 497 div 2 B

    B. Turn the Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. Lesson 11 One good turn deserves another

    Text I was having dinner at a restaurant when Tony Steele came in. Tony worked in a layer's office y ...

  6. webrtc进阶-信令篇-之三:信令、stun、turn、ice

    webRTC支持点对点通讯,但是webRTC仍然需要服务端:  . 协调通讯过程中客户端之间需要交换元数据,    如一个客户端找到另一个客户端以及通知另一个客户端开始通讯.  . 需要处理NAT(网 ...

  7. HDU-4869 Turn the pokers

    原题:  Turn the pokers       思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面 ...

  8. jQuery+turn.js翻书、文档和杂志3种特效演示

    很好用的一款插件jQuery+turn.js翻书.文档和杂志3种特效演示 在线预览 下载地址 实例代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

  9. poj-1314 Finding Rectangles

    题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...

随机推荐

  1. Hive学习笔记一

    1. Load的使用 //在1.x版本中定义long数据类型会报错(用bigint代替) create table t_load_stu(name string,age bigint) row for ...

  2. nginx file not found 错误处理小记

    安装完php php-fpm nginx 后访问php出现file not found错误,html就没问题配置文件server 段如下 server { listen 80; server_name ...

  3. dubbo协议下的单一长连接与多线程并发如何协同工作

    上班的路上突然就冒出了这么个问题:既然在dubbo中描述消费者和提供者之间采用的是单一长连接,那么如果消费者端是高并发多线程模型的web应用,单一长连接如何解决多线程并发请求问题呢? 其实如果不太了解 ...

  4. element ui中dialog相关问题

    一,今天需要在dialog里面引入另一个页面,就是打开dialog显示该页面(把页面放到dialog中),引入的语句如下: <iframe src="view?path=rkdj_b& ...

  5. 三种方式控制GPIO

    BBB为REV C,emmc4G版本,系统为Debian 7.9 wheezy (2015.11.12),内核为Linux 3.8.13.使用命令cat /etc/dogtag查看 查看系统信息的四种 ...

  6. Unable to find the wrapper ”https” - did youforget to enable it when you configured PHP?

    Unable to find the wrapper ”https” - did youforget to enable it when you configured PHP? 这是在Windows的 ...

  7. json.loads()的字符串中为单引号引发的错误

    如下错误属于弱智错误,但是错的原因让我无语,所以记录一下 str2="{'card':6217001650004184441}"print(json.loads(str2)) Tr ...

  8. QQ号码正则判断

    <!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">   ...

  9. tornado 和 djanjo 转义处理对比

    tornado tornado默认是转义所有字符,比较安全,但有时候我们的确需要把字符当做html来解析处理,因此我们需要做些处理. 所有的模板输出都已经通过 tornado.escape.xhtml ...

  10. sshd_config

    1.sshd_config 选项不区分大小写,参数区分大小写. sshd_config选项及参数 选项 默认值 说明 AcceptEnv 不接受任何值   AddressFamily any any/ ...