Codeforces-1008-B(水)
Codeforces 1008B - Turn the Rectangles
題目原址
[http://codeforces.com/contest/1008/problem/B]
題意
輸入一個數 n,接下來 n 對數 wi , hi , 你可以交換其中的 wi 和 hi 使得陣列 hn 為廣義單調遞減。
題解
用另一變數儲存 hi−1 通過對 wi 和 hi 比較,選出符合廣義單調遞減的最大值作為新的 hi−1 ,當不存在時,返回 NO 。
實現
#include <stdio.h>
int main(){
int n;
scanf("%d",&n);
int w,h;
int t=0;//儲存上次的h
while(n--){
scanf("%d %d",&w,&h);
if(w > h)
w^=h^=w^=h; //交換wh,使得h>=w
if(t >= h || !t)//如果h小於等於上次的h,或者這是第一次
t = h;
else if(t >= w)
t = w;
else
return 0*printf("NO\n");
}
printf("YES\n");
return 0;
}
相關推薦
Codeforces-1008-B(水)
Codeforces 1008B - Turn the Rectangles 題目原址 [http://codeforces.com/contest/1008/problem/B] 題意 輸入一個數 n,接下來 n 對數
Codeforces-1060-B(水)
Codeforces 1060B - Maximum Sum of Digits 題目原址 [http://codeforces.com/contest/1060/problem/B] 題意 任意給一個數 n ,把他分解為 n = a + b ,求 a 與 b 中的每一位數相
Codeforces-1011-C(水)
Codeforces 1011C - Fly 題目原址 [http://codeforces.com/contest/1011/problem/C] 題意 n 是加上地球和火星的總星球數,m 是火箭不帶燃料的質量。 a[i] 和 b[i] 是每個星球起飛和降落 1 噸物質所需
Codeforces-1006-C(水)
Codeforces 1006C - Three Parts of the Array 原題地址 [http://codeforces.com/contest/1006/problem/C] 題意 給一個數組 a[i] ,當從0項開始的一段數列之和等於從最後一項結束的一段數列
HDU 2035 人見人愛A^B(水~)
Description 求A^B的最後三位數表示的整數。 Input 輸入資料包含多個測試例項,每個例項佔一行,由兩個正整數A和B組成(1<=A,B<=10000),如果A=0, B=
CodeForces 884A.B.C Book Reading(水) | Japanese Crosswords Strike Back(水) | Bertown Subway(DFS)
有序 req air 改變 rain ont ring cal word Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book
Codeforces Round #277 (Div. 2) A (水題)B(水題) C(貪心)
A. Calculating Function For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + .. + ( - 1)nn Your task is to calcul
codeforces 508 B Anton and currency you all know(水)
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations
CodeForces 817 B.Makes And The Product(水~)
Description 給出n個正整數ai,問有多少三元組(i,j,k)滿足1≤i<j<k≤n且ai⋅aj⋅ak最小 Input 第一行一整數n表示序列長度,之後輸入n個整數ai(3≤
Newcoder 39 B.儲物點的距離(水~)
Description 一個數軸,每一個儲物點會有一些東西,同時它們之間存在距離。 每次給個區間 [ l
Newcoder 16 B.Distance(水~)
Description F S T
A + Reverse B(水題一發)
You are given numbers a and b. Calculate the sum of a and reverse of b. A reverse of a number is a number which contains the same digits in revers
Codeforces Round #515 (Div. 3) B(模擬)
題意:在數列中值為1的位置有1個加熱器,它能覆蓋它的左邊第 r-1 位置到它的右邊 r-1 的位置,問最少多少個加熱器能覆蓋整個區間。 思路:模擬這個過程,首先now=1,然後遍歷所有位置,找到最遠的滿足now這個位置能加熱的點,再另now=i+r-1+1,之所以要+1,是因為,i+r-1這個位
【Ciel and Robot 】【CodeForces - 322C】(水題)
題目: Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string&nb
Newcoder 132 B.送分題(水~)
Description 資料結構之神cczcczccz又在出毒瘤資料結構了 神出了這樣一個題: 給你三個數,在這三個數中間任意加∗*∗或者是+++,然後可以隨便打括號,只要這個表示式合法 比如說1231
HDU-2033-人見人愛A+B(水水水)
HDOJ上面已經有10來道A+B的題目了,相信這些題目曾經是大家的最愛,希望今天的這個A+B能給大家帶來好運,也希望這個題目能喚起大家對ACM曾經的熱愛。 這個題目的A和B不是簡單的整數,而是兩個時間,A和B 都是由3個整陣列成,分別表示時分秒,比如,假設A為34 45 56
Newcoder 83 B.沃老師學生的成績(水~)
Description 學生的作文成績時,給每位學生的分數都是一個小於101010的非負小數。 Amy8.999999999999999999999999999999999999999990000Amy
Newcoder 58 B.棧和排序(水~)
Description 給你一個1→n1\rightarrow n1→n的排列和一個棧,入棧順序給定 你要在不打亂入棧順序的情況下,對陣列進行從大到小排序 當無法完全排序時,請輸出字典序最大的出棧序列
Jack的A+B (水題 STL實現 )
題面 : 現在有整數a,b,請按西方數字數量級方式輸出a+b 輸入 題目有多組測試資料 每組輸入兩個整數a,b (0<=a,b<=10000000) 輸出 輸出西方數字數量級的a+b 樣例輸入 Copy 999 1 36 30 100000 100 樣例輸
【打CF,學演算法——一星級】CodeForces 617D Polyline(水題)
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it pa