| ||||||||||
| 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 | |||||||||
按l和w排序两次,取最小的sum,有问题吗?#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;
typedef struct sticks {
int x;
int y;
}stick;
stick aa[5000];
int compare_x( const void* a, const void* b ) {
stick* arg1 = (stick*) a;
stick* arg2 = (stick*) b;
if( arg1->x < arg2->x ) return -1;
else if( arg1->x == arg2->x )
return arg1->y-arg2->y;
else return 1;
}
int compare_y( const void* a, const void* b ) {
stick* arg1 = (stick*) a;
stick* arg2 = (stick*) b;
if( arg1->y < arg2->y ) return -1;
else if( arg1->y == arg2->y )
return arg1->x-arg2->x;
else return 1;
}
int main()
{
int M;
int Tcase;
cin>>Tcase;
while(Tcase-->0)
{
cin>>M;
for(int i=0;i<M;i++)
cin>>aa[i].x>>aa[i].y;
qsort(aa,M,sizeof(stick),compare_x);
int sum1=0;
for(int i=0;i<M-1;i++)
{
if(aa[i].y>aa[i+1].y)
sum1++;
}
qsort(aa,M,sizeof(stick),compare_y);
int sum2=0;
for(int i=0;i<M-1;i++)
{
if(aa[i].x>aa[i+1].x)
sum2++;
}
if(sum1>sum2)
cout<<sum2+1<<endl;
else
cout<<sum1+1<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator