现在的位置: 首页 > 综合 > 正文

uva 10763 – Foreign Exchange 水

2013年03月07日 ⁄ 综合 ⁄ 共 745字 ⁄ 字号 评论关闭

     要求严格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");

    }
}

抱歉!评论已关闭.