pku acm 1065

来源:互联网 发布:淘宝评价怎么写50字 编辑:程序博客网 时间:2024/06/04 00:32

//贪心算法

#include <iostream>#include <cstdio>#include <list>#include <algorithm>using namespace std;typedef pair<int,int> PINTINT;bool cmp1(PINTINT p1, PINTINT p2){if (p1.first < p2.first)return true;if (p1.first > p2.first)return false;//p1.first == p2.firstif (p1.second < p2.second)return true;if (p1.second > p2.second)return false;//p1 == p2return false;}int main(){freopen("in.txt","r",stdin);PINTINT tpair;list<PINTINT> listpairs;list<PINTINT>::iterator it;int time;int t,n;cin>>t;while(t--){cin>>n;listpairs.clear();while (n--){cin>>tpair.first>>tpair.second;listpairs.push_back(tpair);}listpairs.sort(cmp1);/*for (it = listpairs.begin();it != listpairs.end(); ++it)cout<<it->first<<" "<<it->second<<endl;*/time = 0;int prev;while(listpairs.size() > 0){it = listpairs.begin();prev = it->second;for (++it;it != listpairs.end();){ if (it->second >= prev){prev = it->second;it = listpairs.erase(it);}else ++it;}listpairs.erase(listpairs.begin());time++;}cout<<time<<endl;}}