设为首页 加入收藏

TOP

poj1083 Moving Tables
2015-07-20 17:21:02 来源: 作者: 【 】 浏览:2
Tags:poj1083 Moving Tables

Moving Tables
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 26782 Accepted: 8962

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 cZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcnJpZG9yIGJldHdlZW4gdGhlIGZyb250IG9mIHJvb20gaSBhbmQgdGhlIGZyb250IG9mIHJvb20gaiBpcyB1c2VkLiBTbywgZHVyaW5nIGVhY2ggMTAgbWludXRlcywgc2V2ZXJhbCBtb3ZpbmcgYmV0d2VlbiB0d28gcm9vbXMgbm90IHNoYXJpbmcgdGhlIHNhbWUgcGFydCBvZiB0aGUgY29ycmlkb3Igd2lsbCBiZSBkb25lIHNpbXVsdGFuZW91c2x5LiBUbyBtYWtlIGl0IGNsZWFyIHRoZSBtYW5hZ2VyIGlsbHVzdHJhdGVkIHRoZQogcG9zc2libGUgY2FzZXMgYW5kIGltcG9zc2libGUgY2FzZXMgb2Ygc2ltdWx0YW5lb3VzIG1vdmluZy4gPGJyPgo8Y2VudGVyPjxpbWcgc3JjPQ=="https://www.cppentry.com/upload_files/article/49/1_ngodi__.gif" alt="\">
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

解题思路:利用房间号分割走廊,每条“子走廊”都设置一个计数器,每经过一次+1,完了最后对计数器快排,最大的次数X10就是答案;

参考代码:

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; int main(){ int t,n,a[401],x,y; cin>>t; while (t--){ cin>>n; memset(a,0,sizeof(a)); for (int i=0;i
      
       >x>>y; if (x>y){ int temp=x; x=y; y=temp; } if (x%2!=0) x++; if (y%2!=0) y++; for (int j=x;j<=y;j+=2) a[j]++; } sort(a,a+401); cout<
       
        


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu4320Arcane Numbers 下一篇ZOJ 1409 Communication System

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C 内存管理 | 菜鸟教 (2025-12-26 20:20:37)
·如何在 C 语言函数中 (2025-12-26 20:20:34)
·国际音标 [ç] (2025-12-26 20:20:31)
·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)