#include <iostream>
#include <fstream>
#include <list>
#include <algorithm>
using namespace std;
inline bool less_l(const pair<int,int> &p1, const pair<int,int> &p2)
{
return (p1.first<p2.first || p1.first==p2.first&& p1.second<p2.second);
}
inline bool less_lw(const pair<int,int> &p1, const pair<int,int> &p2)
{
return (p1.first<=p2.first && p1.second<=p2.second);
}
void count_lw(list<pair<int,int> > &a, int begin, int len, int &count)
{
a.sort(less_l);
list<pair<int,int> >::iterator it;
list<pair<int,int> >::iterator temp_it;
while(!a.empty())
{
count++;
pair<int,int> temp=*a.begin();
for(it=a.begin();it!=a.end();)
{
if(less_lw(temp,*it))
{
temp=*it;
temp_it=it;
++it;
a.erase(temp_it);
}
else
{
++it;
}
}
}
}
int main()
{
ifstream cin("1.txt");
int T,n;
int i,j;//,k;
cin>>T;
pair<int,int> temp;
int l,w;
list<pair<int,int> > a;
int count;
for(i=0;i<T;i++)
{
a.clear();
count=0;
cin>>n;
for(j=0;j<n;j++)
{
cin>>l>>w;
a.push_back(make_pair(l,w));
}
count_lw(a,0,n, count);
cout<<count<<endl;
}
return 0;
}
zoj 1025 贪心
最新推荐文章于 2019-07-11 16:56:30 发布