STL初入

来源:互联网 发布:人证比对软件 编辑:程序博客网 时间:2024/06/07 01:47
昨日思路有缺陷再加一个vector排序即可代码如下:
#include#include#include#includeusing namespace std;typedef struct Point{    int x,y;    Point (int x= 0,int y = 0):x(x),y(y){}};vector dot,dot1;bool flag;Point operator (const Point& A, const Point& B){    return Point(A.x B.x,A.y B.y);}bool compare(const Point& A, const Point& B){    if(A.x != B.x)        return A.x    else        return A.y}bool compare1(const Point& A, const Point& B){    if(A.x != B.x)        return A.x    else        return A.y>B.y;}int main(){    //freopen("in.txt","r",stdin);    int T;    cin>>T;    while(T--)    {        dot.clear();        dot1.clear();        int n;        Point spot;        cin>>n;        for(int i = 0; i < n; i )        {            cin>>spot.x>>spot.y;            dot.push_back(spot);            dot1.push_back(spot);        }        sort(dot.begin(),dot.end(),compare);        sort(dot1.begin(),dot1.end(),compare1);        flag = true;        int tmp = dot[0].x dot1[n-1].x;        for(int i = 0; i < n/2; i )        {            if(dot[i].x dot1[n-1-i].x != tmp           || dot[i].y != dot1[n-i-1].y)            {                flag = false;                break;            }        }        if(flag) cout<<"YES"<
0 0