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 file. 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 3 + N -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 一道思维题,主要思路是不要拘泥于路径和搬运的顺序(我一开始就是过分关于与顺序,打算用map映射来一步一步的做,发现太过麻烦吐血放弃!)。思考后,其实可以用一个vectoe或者array把每一次路过的地方记录并加起来。
  坑:注意40>>30 30>>40这两种方向也是要考虑的。
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
for (int i = ; i < n; ++i)
{
int k;
cin>>k;
vector<int> v(,);
for (int j= ; j < k; ++j)
{
int a,b,t;
cin>>a>>b;
if(a>b) {t=a;a=b;b=t;}
for(int l=(a-)/;l<=(b-)/;l++)
{
v[l]++;
}
}
sort(v.begin(),v.end());
cout<<v[]*<<endl;
}
return ;
}

poj1083的更多相关文章

  1. POJ1083 Moving Tables

    POJ1083 Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35297   Accepted: ...

  2. 解题报告:poj1083 Moving tables

    2017-09-02 19:49:59 writer:pprp 题意说明: 比较简单的题,一开始被吓到了,后来才发现,其实可以用很简单的方法就可以解决: 就是在这样的房间中如果在i 和 j 中之后的1 ...

  3. Moving Tables(贪心或Dp POJ1083)

    Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28304   Accepted: 9446 De ...

  4. poj1083 贪心

    K - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit ...

  5. poj1083 思考题

    http://poj.org/problem?id=1083 Description The famous ACM (Advanced Computer Maker) Company has rent ...

  6. poj1083,基本互斥问题

    题意:南北两侧各有200个房间,两侧房间之间有一个走廊 现在需要把桌子从这400个房间之中搬进搬出,每一张桌子需要10分钟时间,如果走廊因为有桌子搬运而占用,则需等待,求共需多少时间(分钟)将桌子搬完 ...

  7. POJ1083 Moving Tables(模拟)

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

  8. 【POJ1083】 Moving Tables (并行的搬运)

    BUPT2017 wintertraining(15) #6E 题意 房间1和2,3和4,...,399和400共用一节走廊,有q次从房间li到ri的搬运桌子,一次搬运10分钟.两个搬运如果走廊有重叠 ...

  9. POJ1083(Moving Tables)--简单模拟

    题目链接:http://poj.org/problem?id=1083 如图所示在一条走廊的两侧各有200个房间,现在给定一些成对的房间相互交换桌子,但是走廊每次只能通过一组搬运, 也就是说如果两个搬 ...

随机推荐

  1. redis——持久化篇

    众所周知,redis是内存数据库,它把数据存储在内存中,这样在加快读取速度的同时也对数据安全性产生了新的问题,即当redis所在服务器发生宕机后,redis数据库里的所有数据将会全部丢失. 为了解决这 ...

  2. [译]2016年深度学习的主要进展(译自:The Major Advancements in Deep Learning in 2016)

    译自:The Major Advancements in Deep Learning in 2016 建议阅读时间:10分钟 https://tryolabs.com/blog/2016/12/06/ ...

  3. 利用反射与dom4j读取javabean生成对应XML和读取XML得到对应的javabean对象集合

    转自:http://blog.csdn.net/zhao19861029/article/details/8473245 首先实现生成对应的JAVAbean的XML文件方法 /** * DMO4J写入 ...

  4. Java程序设计笔记

    程序:编写Java程序,此程序从命令行接收多个数字,求和之后输出结果. 设计思想:首先在程序中设置关于参数个数的长度的公式,用.length公式读出用户所设置的参数的个数,参数默认为字符串类型,利用强 ...

  5. php版本引起的const问题

    刚刚遇到一个问题,类中定义了一个常量: const USER = ['aa', 'bb', 'cc']; 在类中的静态函数中调用以上常量不会出错.网站中所有的网页均能正常打开. 而当push到线上后, ...

  6. LSD-SLAM深入学习(3)-代码解析

    前言 在LSD-SLAM深入学习(2)中我们已经对算法进行分析,此处假设读者对于ros的基本操作都已经很熟悉,而且已经编写了一定量的的代码,我们直接上干货.此处分析的程序如下 main_live_od ...

  7. Linux 流程控制语句 if else、for、while、until

    1. 单分支if条件语句 书写方式1: if [ 条件判断式 ]; then 执行程序代码 fi 书写方式2: if [ 条件判断式 ] then 执行程序代码 fi 举例: if [ $rate - ...

  8. 微信公众平台创建自定义菜单中文编码导致system error

    创建包含了中文的自定义菜单时总是返回{"errcode":-1,"errmsg":"system error"},要将编码方式设置为UTF- ...

  9. 哈哈,修改PHP5.4.44语法成功

    作为一个脚本语言,面向对象的继承基本上不想用到,强类型比较也想使用==直接比较.作为专业程序员不想让PHP解释器代劳过多. 修改了这个MOD版本,效果杠杠的.

  10. 传统B2B中小型企业如何做好全网营销

    优网特独创全网营销服务理念,全网营销即以企业网站推广为核心,通过SEO.SEM.BBS营销.博客营销.微营销.即时通讯营销.网络口碑营销.视频营销.邮件营销.SNS营销等网络营销手段,全面提升企业网站 ...