Moving Tables

Problem Description

The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.

Input

The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.

Output

The output should contain the minimum time in minutes to complete the moving, one per line.

Sample Input

3

4

10 20

30 40

50 60

70 80

2

1 3

2 200

3

10 100

20 80

30 50

Sample Output

10

20

30

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f struct node
{
int a,b,flag;
} p[10000]; bool cmp(node a,node b)
{
return a.a<b.a;
} int main()
{
int m,t,n;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
memset(p,0,sizeof p);
for(int i=0; i<n; i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
if(p[i].a>p[i].b)
swap(p[i].a,p[i].b);
if(p[i].a%2==0)
p[i].a--;
if(p[i].b%2)
p[i].b++;
}
sort(p,p+n,cmp);
int cnt=0;
int ans=0; for(int i=0; i<n; i++)
{
if(p[i].flag==0)
{
ans++;
p[i].flag=1;
int cur=i;
int k=i;
while(k<n)
{
if(p[k].a>p[cur].b&&p[k].flag==0)
{
cur=k;
p[cur].flag=1;
}
k++;
}
}
}
printf("%d\n",ans*10);
}
}
return 0;
}

最新文章

  1. windows和linux之间“/”, &quot;\\&quot;的区别
  2. HTML常用标签总结
  3. 【iOS测试】【随笔】帧率FPS评测
  4. 分享Kali Linux 2016.2第49周镜像文件
  5. wicket基础应用(3)——wicket控件的隐藏和显示
  6. 爆炸吧 js dom ---------&gt; boom
  7. hdu 4465 Candy
  8. 求职基础复习之快速排序c++版
  9. 学习面试题Day04
  10. C#如何以管理员身份运行程序(转)
  11. COM Interop
  12. spring mvc:ueditor跨域多图片上传失败解决方案
  13. poj 1704 Georgia and Bob(阶梯博弈)
  14. 注册中心(Eureka)
  15. Golang实现requests库
  16. AES 加密与解密
  17. Linux操作系统df相关问题解惑
  18. JavaWeb练习-网上名片管理系统
  19. egret 取消自动连接github
  20. appium:运行脚本时,报404的解决办法

热门文章

  1. hibernate的异常 Session was already closed
  2. scala-- 内建控制结构
  3. break、continue、pass介绍
  4. Eclipse安装教程
  5. Java RSA 生成公钥 私钥
  6. Java的反射和代理以及注解
  7. window环境mysql解压版配置
  8. 根据二进制和十进制转换规则转换成游戏[xyytit]
  9. js Array Map and Set
  10. struts框架值栈问题二之值栈的内部结构