[Codeforces]1008B. Turn the Rectangles

題目URL:http://codeforces.com/contest/1008/problem/B
第一組取最大,後面判斷是否有遞減,可以組成任一組遞減即為YES。


#include<bits/stdc++.h>
using namespace std;
map<int,int> a,b;
int num,maxa,maxb,minu;
main()
{
    int deter=0;
    cin >> num;
    for(int i=0;i<num;i++)
    {
        cin >> a[i] >> b[i];
    }
    maxa=max(a[0],b[0]);
    for(int i=1;i<num;i++)
    {
        //cout << maxa << endl;
        maxb=max(a[i],b[i]);
        minu=min(a[i],b[i]);
        if(maxa<maxb)
        {
            if(maxa<minu)
            {
                deter=1;
                break;
            }
            else
            {
                maxa=minu;
            }
        }
        else if(maxa>=maxb)
        maxa=maxb;
    }
    if(deter) return cout << "NO" ,0;
    cout << "YES"<< endl;
    return 0;
}

留言

這個網誌中的熱門文章

[ZJ] b229: TOI 2009 第一題:路徑問題

交大資工(APCS組)(面試&心得)

滿是挫傷的ION CAMP