Turn the Rectangles 1008B
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).
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.
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).
3
3 4
4 6
3 5
YES
2
3 4
5 5
NO
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的更多相关文章
- 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 ...
- Codeforces Round #497 (Div. 2)B. Turn the Rectangles
Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...
- 2018SDIBT_国庆个人第一场
A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...
- CF 497 div 2 B
B. Turn the Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 ...
- webrtc进阶-信令篇-之三:信令、stun、turn、ice
webRTC支持点对点通讯,但是webRTC仍然需要服务端: . 协调通讯过程中客户端之间需要交换元数据, 如一个客户端找到另一个客户端以及通知另一个客户端开始通讯. . 需要处理NAT(网 ...
- HDU-4869 Turn the pokers
原题: Turn the pokers 思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面 ...
- jQuery+turn.js翻书、文档和杂志3种特效演示
很好用的一款插件jQuery+turn.js翻书.文档和杂志3种特效演示 在线预览 下载地址 实例代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...
- poj-1314 Finding Rectangles
题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...
随机推荐
- jquery load()函数和window.onload事件
我想用jquery load()一个饼状图页面, 但是load不出来 代码如下: 后来百度了一下,解决办法如下: window.onload事件只有在文档载入的时候才会执行的,你载入子页面不会触发这个 ...
- WordPress更换主题空白问题
刚才尝试着更换了一个主题,后来发现预览主页的时候是一片空白.查了很多资料,有说是index.php的权限问题,有说是插件问题,有说是UTL-8编码的问题,我都试过了,发现都不行,后来仔细研究了一下,发 ...
- 详解http和https的作用与区别
PS: https就是http和TCP之间有一层SSL层,这一层的实际作用是防止钓鱼和加密.防止钓鱼通过网站的证书,网站必须有CA证书,证书类似于一个解密的签名.另外是加密,加密需要一个密钥交换算法, ...
- ueditor 正在读取目录
ueditor 版本为1.3.6 项目版本为2.0 引用 <script src="../ueditor/ueditor.config.js" type="tex ...
- Jmeter(二十三)Jmeter-Question之“批量造数据”
日常工作中,无论是在做功能测试.接口测试还是性能测试,经常会有这么一个场景出现,“那个谁谁谁,帮我加几条订单”,“那个某某某,给购物车增添几个产品”,“在数据库加几百条数据”...等等,通常少数量,或 ...
- JS+Ajax+Servlet:记录页面访问时间
1.前端JS记录页面访问时间 1.1JQuery版本: <script type="text/javascript" src="js/jquery.min.js&q ...
- C#中常用的单词
visual 可见的 studio 工作室 dot 点 net 网 sharp 尖端的,锋利的. framework 骨架,构架,框架 beta 测试版,试用版 XML(全称:eXtensible M ...
- Solr中使用游标进行深度分页查询以提高效率(适用的场景下)
通常,我们的应用系统,如果要做一次全量数据的读取,大多数时候,采用的方式会是使用分页读取的方式,然而 分页读取的方式,在大数据量的情况下,在solr里面表现并不是特别好,因为它随时可能会发生OOM的异 ...
- SpringBoot项目启用本地Tomcat
1.修改pom.xml文件,配置<packaging>war</packaging>,使其发布的时候打包成war包 <groupId>com.owlforest&l ...
- 变量,if.elif .else判断
一,计算机的了解 基本组成:主板+cpu+内存 cpu: 主频, 核数(16) 内存:大小(8G, 16G, 32G) 型号: DDR3, DDR4, DDR5, 主频(海盗船,玩家国度) ...