-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdu1050.cpp
71 lines (68 loc) · 1.15 KB
/
hdu1050.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
using namespace std;
struct MOVING{
int from,to;
bool isDone;
}moving[200];
void qsort(int l, int r){
if(l>=r)
return;
int i=l;
int j=r+1;
MOVING key=moving[l];
while(i<j){
while(i<j&&moving[--j].from>=key.from);
moving[i]=moving[j];
while(i<j&&moving[++i].from<=key.from);
moving[j]=moving[i];
}
moving[i]=key;
qsort(l,i-1);
qsort(i+1,r);
}
int main(){
int t,n;
while(cin>>t){
for(int i=0;i<t;i++){
cin>>n;
for(int j=0;j<n;j++){
cin>>moving[j].from>>moving[j].to;
moving[j].isDone=false;
if(moving[j].from>moving[j].to){
int temp=moving[j].from;
moving[j].from=moving[j].to;
moving[j].to=temp;
}
if(moving[j].to%2==1){
moving[j].to++;
}
if(moving[j].from%2==0){
moving[j].from--;
}
}
qsort(0,n-1);
int ans=0;
while(true){
ans+=10;
bool isFinish=true;
int now=0;
for(int j=0;j<n;j++){
if(!moving[j].isDone){
if(moving[j].from>now){
now=moving[j].to;
moving[j].isDone=true;
}
else{
isFinish=false;
}
}
}
if(isFinish){
break;
}
}
cout<<ans<<endl;
}
}
return 0;
}