[POJ1083]Moving Tables
来源:互联网 发布:ping 域名 ip不一样 编辑:程序博客网 时间:2024/05/29 03:14
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 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.
题意:
房间布置如同第一个表格,经理需要移动桌子(移动一次十分钟), 桌子可以同时移动(条件允许一次移动完毕也可以),但是不能共用走廊,问移动所有桌子最短所需的时间。
题解:用走廊的位置作下标
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int N=210;int T, n, used[N], ans, sum;int main() {for( scanf( "%d", &T ); T; T-- ) {memset( used, 0, sizeof used );ans=sum=0;scanf( "%d", &n );for( int i=1; i<=n; i++ ) {int s, e;scanf( "%d%d", &s, &e );if( s>e ) swap(s, e);s=(s+1)>>1, e=(e+1)>>1;used[s-1]++; used[e]--;}for( int i=0; i<=200; i++ ){ans+=used[i];sum=max( ans, sum );}printf( "%d\n", sum*10 );}return 0;}/*样例:122 56 7输出20*/
阅读全文
0 0
- POJ1083 Moving Tables
- poj1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083--Moving Tables
- POJ1083 Moving Tables
- poj1083:moving tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables
- poj1083-Moving Tables-贪心
- POJ1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables解题报告
- 【离散化】poj1083 Moving Tables
- POJ1083,Moving Tables,好纠结的题
- exit()和析构函数的关系
- HBase基于Hadoop2.5完全分布式HA环境搭架
- json xml解析
- 5-13 日K蜡烛图 (15分)
- Storm中worker, executor,task之间的关系:
- [POJ1083]Moving Tables
- 时间序列数据的首选神经网络
- 系统广播的收到短信和来电/去电
- C++ STL使用,以及注意事项
- MYSQL的REPLACE和ON DUPLICATE KEY UPDATE使用
- RecycleView源码浅析之Recycler+滑动
- Linux下的tar压缩解压缩命令详解
- 使用exportfs命令来重新加载/etc/exports文件
- 【Android Studio】Live Template