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 |
Re:好不容易过的,happyingIn Reply To:好不容易过的,happying Posted by:knuthocean at 2005-03-24 21:58:19 谁能帮忙看看错哪了?谢谢!!! #include <set> #include <iostream> using namespace std; class Pair { public: int less; int bigger; }; bool operator<(const Pair& p1,const Pair& p2) { if(p1.bigger<p2.bigger) return true; else if(p1.bigger==p2.bigger) { if(p1.less<p2.less) return true; else return false; } else return false; } int main(int argc, char* argv[]) { set<Pair> pairs; Pair p; int num; cin>>num; int i=0; while(i<num) { cin>>p.less>>p.bigger; pairs.insert(p); i++; } set<Pair>::iterator it1,it2; it1=pairs.begin(); it2=pairs.begin(); it2++; while(it2!=pairs.end()) { if((*it2).less<=(*it1).less) { pairs.erase(it1); it1=it2; it2++; } else if((*it2).less>(*it1).less&&(*it2).less<=(*it1).bigger) { (*it2).less=(*it1).less; pairs.erase(it1); it1=it2; it2++; } else { it1++; it2++; } } it1=pairs.begin(); while(it1!=pairs.end()) { cout<<(*it1).less<<' '<<(*it1).bigger<<'\n'; it1++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator