| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大牛们 帮忙看一下 为什么过不了啊先对X排序 再对相同X的Y排序
#include<iostream>
#include<algorithm>
using namespace std;
#define mmax 50050
struct node
{
int x,y;
}nod,tem,aa[mmax];
int n;
int num;
bool cmpx(node a,node b)
{
if(a.x>b.x)
return 0;
else
return 1;
}//why? 0 1 exchange
bool cmpy(node a,node b)
{
if(a.x==b.x)
if(a.y>=b.y)
return 1;
else return 0;
return 1;
}
void init()
{
sort(aa,aa+n,cmpx);
sort(aa,aa+n,cmpy);
}
int main()
{ num=0;
n=0;
while(1)
{
cin>>n;
if(!n)
break;
int i;
for(i=0;i<n;i++)
cin>>aa[i].x>>aa[i].y;
init();
int maxy=aa[0].y;
num=1;
for(i=1;i<n;i++)
{
if(aa[i].x==aa[i-1].x)
continue;
else
{
if(aa[i].y>maxy)
{ num++;maxy=aa[i].y;}
}
}
cout<<num<<endl;
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator