click here to check the problem:http://acm.hdu.edu.cn/showproblem.php?pid=1050
AC code:
#include<iostream>
#include<string>
#include <cstdio>
#include <cmath>
#include<vector>
#include<algorithm>
#include<sstream>
#include<cstdlib>
using namespace std;
struct node{
int x,y;
};
bool comp(node a,node b){
return a.x<b.x;
}
bool compatibel(node a ,node b){
if(a.y+1==b.x)return false;
else return a.y<b.x;
}
int main()
{
int t,n;
cin>>t;
vector<node> buf;
node tmp;
while(t--)
{
cin>>n;
for(int i=0;i<n;i++)
{
int a,b;
cin>>a>>b;
tmp.x=a<b?a:b;
tmp.y=a<b?b:a;
buf.push_back(tmp);
}
sort(buf.begin(),buf.end(),comp);
int t=10;
if(n==1){cout<<10<<endl;}
else {
for(vector<node>::size_type i=0;i<buf.size()-1;i++)
{
tmp=buf[i];
if(compatibel(tmp,buf[i+1])){continue;}
t+=10;
}
}
cout<<t<<endl;
buf.clear();
}
return 0;
}