其他分享
首页 > 其他分享> > poj 1065(注意sort函数的使用)

poj 1065(注意sort函数的使用)

作者:互联网

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 5005
typedef struct node{
    int x,y;
}Point;
//int cmp(Point p1,Point p2){
//    if(p1.x<=p2.x&&p1.y<=p2.y)return true;
//    else if(p1.x>=p2.x&&p1.y>=p2.y)return false;
//}
Point point[maxn]; 
int cmp(Point p1,Point p2){
    if(p1.x<p2.x)return true;
    return false;
}
int main(){
    int t,n,sum,i,j,tmp_x,tmp_y;
    bool flag[maxn];
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d%d",&point[i].x,&point[i].y);
        }
        sort(point,point+n,cmp);
        memset(flag,false,sizeof flag);
        sum = 0;
        for(j=0;j<n;j++){
            i=0;
            while(i<n&&flag[i])i++;
            if(i==n)break;
            tmp_x = point[i].x;
            tmp_y = point[i].y;
            for(;i<n;i++){
                if(!flag[i]&&point[i].x>=tmp_x&&point[i].y>=tmp_y){
                    flag[i] = true;
                    tmp_x = point[i].x;
                    tmp_y = point[i].y;
                }
            }
            sum++; 
        }
        cout<<sum<<endl;
    }
    return 0;
}

 

标签:sort,tmp,p1,point,int,Point,1065,p2,poj
来源: https://www.cnblogs.com/stevenzrx/p/15589238.html