入门经典上面关于BST树应用的一个题~用标准模板库做就比较简单了~唯一需要注意一点的就是最后没有那个多的换行符,否则WA~
代码:
#include<cstdio>
#include<cstring>
#include<set>
#include<iostream>
using namespace std;
struct Node
{
int x,y;
Node(int a,int b)
{
x=a;
y=b;
}
bool operator < (const Node a)const
{
if(x==a.x)
return y<a.y;
return x<a.x;
}
};
multiset<Node> s;
multiset<Node>::iterator it;
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
s.clear();
int n;
scanf("%d",&n);
printf("Case #%d:\n",cas++);
while(n--)
{
int ita,itb;
scanf("%d%d",&ita,&itb);
Node itc=Node(ita,itb);
it=s.lower_bound(itc);
if(it==s.begin()||(--it)->y>itb)
{
s.insert(itc);
it=s.upper_bound(itc);
while(it!=s.end()&&it->y>=itb)
s.erase(it++);
}
printf("%d\n",s.size());
}
if(T>0)
printf("\n");
}
return 0;
}