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 |
C++用map,30行代码#include <cstdio> #include <climits> #include <map> #include <set> using namespace std; typedef map<int,int>::iterator it; int main() { int T; scanf("%d", &T); while(T--) { map<int,int> m; m[INT_MIN] = m[INT_MAX] = -1; int n, x, y; scanf("%d", &n); while(n--) { scanf("%d%d", &x, &y); ++ y; it l = m.lower_bound(x); it r = m.upper_bound(y); it t = r; -- t; int p = t->second; for(it i=l; i!=r; ) m.erase(i++); m[x] = n; m[y] = p; } set<int> s; for(it i=m.begin(); i!=m.end(); ++i) s.insert(i->second); printf("%d\n", s.size() - 1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator