hdu 1050 Moving Tables

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 



10 20 
30 40 
50 60 
70 80 

1 3 
2 200 

10 100 
20 80 
30 50


Output for the Sample Input

10 
20 
30

 

题意及分析:

在一层楼房里有编号1-400的房间,奇数号和偶数号分列两边。现在有一些桌子要移动,但是走廊的原因,一段路只能容纳下一张桌子的移动工作。(也就是说不同路段就可以同时进行)有一些桌子要从一个房间移动到另一些房间,要你求所需的最短的时间。

贪心的想法是:先按房间的编号排序,把没有冲突的移动找出来。把有冲突的移动保存。然后再从保存的移动里找出那些互相不矛盾的移动。直到所有移动全部完成。

AC代码:

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
        #include 
        
          #include 
         
           #include 
          
            #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; struct node { int id; int s; //小的编号 int t; //大的房间编号 }a[5010],que[100010]; int cmp(node a,node b) { if(a.s==b.s) //按编号的大小排序 return a.t 
           
             now.t) //选出不相互冲突的移动 ,注意不能包括等号 { now=tmp; flag[i]=1; } else { if(!vis[tmp.id]) { vis[tmp.id]=1; //标记移动,避免重复入队 que[rear++]=tmp; } } } } printf("%d\n",10*num); } return 0; } 
            
           
          
        
      
      
     
     
    
    
   
   

 还有一种思路就是,把处在对门的两个编号变为一个编号。那么这些1-400的编号就变成了1-200的编号。再然后计算每一个房间所处路段经过的次数,取其中的最大值。

代码如下:

#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      
#include
      
      
       
       
#include
       
        #include 
        
          #include 
         
           #include 
          
            #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; int cnt[1000]; int main() { int i,n,t,j; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(cnt,0,sizeof(cnt)); int ma=-10; for(i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); x=(x+1)/2; //将原来为奇偶的编号重新赋值 y=(y+1)/2; int t1=min(x,y); int t2=max(x,y); for(j=t1;j<=t2;j++) { ++cnt[j]; //每个编号对应的路段,如果被利用过就+1 if(cnt[j]>ma) ma=cnt[j]; } } printf("%d\n",ma*10); } return 0; } 
           
          
        
      
      
     
     
    
    
   
   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值