zoukankan      html  css  js  c++  java
  • Codeforces Round #497 (Div. 2) B. Turn the Rectangles

    B. Turn the Rectangles
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    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 (1n1051≤n≤105) — the number of rectangles.

    Each of the next nn lines contains two integers wiwi and hihi (1wi,hi1091≤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.

    翻转一堆四边形使得四边形队列高度递减

    从前往后保留小于等于上一个的边长最大值


    #include <iostream>
    using namespace std;
    
    typedef long long ll;
    
    int main()
    {
    	ll N, ta, tb, mt;
    	
    	cin>>N;
    	
    	N--;
    	
    	cin>>ta>>tb;
    	
    	mt = max(ta, tb);
    	
    	while(N--)
    	{
    		cin>>ta>>tb;
    		
    		if(min(ta, tb) > mt)
    		{
    			cout<<"NO"<<endl;
    			goto l1;
    		}
    			
    		
    		else
    		{
    			if(max(ta, tb) <= mt)
    				mt = max(ta, tb);
    				
    			else
    				mt = min(ta, tb);
    		}	
    	}
    	cout<<"YES"<<endl;
    	
    	l1:
    		
    	return 0;
    }
    



  • 相关阅读:
    艾伟:一个让人遗忘的角落—Exception(二) 狼人:
    艾伟:ASP.NET 2.0的编译模型 狼人:
    艾伟:VS 2008快捷键 狼人:
    艾伟:[一步一步MVC]第一回:使用ActionSelector控制Action的选择 狼人:
    艾伟:C# Design Patterns (3) Decorator 狼人:
    艾伟:详解AJAX核心 —— XMLHttpRequest 对象 (下) 狼人:
    艾伟:HTML重构:战略篇 狼人:
    艾伟:WCF安全之EndPointIdentity 狼人:
    翻转句子中单词的顺序
    menucool
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270588.html
Copyright © 2011-2022 走看看