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 |
小生用了map…657ms…红黑树果然效率低啊……rt... 估计如果不用scanf和printf就TLE了……想办法优化优化…… //1089 #include <iostream> #include <map> using namespace std; int main() { map<int,int> p; int n; scanf("%d",&n); while(n--) { int l,r; scanf("%d%d",&l,&r); if(p.find(l)!=p.end()) { if(p.find(l)->second<r) p.find(l)->second=r; } else p.insert(pair<int,int>(l,r)); } map<int,int>::iterator s=p.begin(); map<int,int>::iterator it; while(s!=p.end()) { int left=s->first; int right=s->second; it=++s; while(it->first<=right && it!=p.end()) { right=(it->second>right)?it->second:right; it++; } printf("%d %d\n",left,right); s=it; } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator