閱讀942 返回首頁    go 阿裏雲 go 技術社區[雲棲]


uva 10763 - Foreign Exchange 水

     要求嚴格a-b,b-a,所以分別對a,b排個序,然後比較是不是嚴格相同

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define INF 1E9
using namespace std;
struct edge
{
    int u,v;
    friend bool operator ==(edge a,edge b)
    {
        return a.u==b.v&&a.v==b.u;
    }
};
edge e[500005];
int a[500005],b[500005];
bool cmpa(int A,int B)
{
    if(e[A].u==e[B].u)return e[A].v>e[B].v;
    return e[A].u>e[B].u;
}
bool cmpb(int A,int B)
{
    if(e[A].v==e[B].v)return e[A].u>e[B].u;
    return e[A].v>e[B].v;
}
int main()
{
    int n;
    while(~scanf("%d",&n),n)
    {
        int i;
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&e[i].u,&e[i].v);
            a[i]=b[i]=i;
        }
        sort(a,a+n,cmpa);
        sort(b,b+n,cmpb);
        for(i=0;i<n&&e[a[i]]==e[b[i]];i++);
        if(i!=n)puts("NO");
        else puts("YES");

    }
}



最後更新:2017-04-03 16:48:43

  上一篇:go CUDA從入門到精通(零):寫在前麵
  下一篇:go 最受歡迎的8位Java大師