贪心,考虑连廊的特殊性即可过了
#include <iostream>
#include <cstdlib>
using namespace std;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
const int MAX_SIZE = 202;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
typedef struct
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int s,t;
bool mark;//标记是否已移动
}Node;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
Node table[MAX_SIZE];
int T,n;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int cmp(const void *a, const void *b)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{//以s为主关键字,t为次关键字升序排列
Node *p,*q;
p = (Node *)a;
q = (Node *)b;
if(p->s != q->s)
return p->s > q->s;
else
return p->t > q->t;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void Solve()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int t1,t2;
int i,j,k,cnt = 0;
int ttime = 0;
for(i = 0; i < n; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{//输入
cin>>t1>>t2;
if(t1 < t2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{table[i].s = t1;table[i].t = t2;}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{table[i].s = t2;table[i].t = t1;}
table[i].mark = false;//未移动
}
qsort(table,n,sizeof(Node),cmp);
for(i = 0; i < n; i++)
if(table[i].mark == false)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
table[i].mark = true;//当然这里标记是毫无意义的
cnt++;
k = i;j = i + 1;
for(;j < n; j++)
if(table[j].mark == false)
if( table[k].t < table[j].s)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(table[k].t % 2)
if(table[j].s == table[k].t +1)continue;
//有走廊的特殊性必须得考虑这种情况
//就像(2,3) and (4,5)是不能同时进行的
table[j].mark = true;
k = j;
cnt++;
if(cnt == n)break;
}
ttime++;
if(cnt == n)break;
}
cout<<ttime*10<<endl;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
while(cin>>T)
while(T--&&cin>>n)
Solve();
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)