zoj 1025 贪心

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值