• Moving Tables


    Total Submissions: 32406   Accepted: 10831

    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 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

    题意:一条走廊,现在要移动桌子,从a房间移动到b房间,有交叉的地方不能同时移,即走廊的宽度只能容纳一个桌子。
    题解:首先将左右的房间进行压缩,如1-2,压缩成1,即相对的房间变成了一个房间。然后一条一条的扫,经过的房间就加上1.最后求出经过房间的最大次数。
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6  
     7 const int maxn=400;
     8 
     9 int kase,n;
    10 int map[maxn];
    11 
    12 int main()
    13 {   cin>>kase;
    14     while(kase--){
    15         cin>>n;
    16         memset(map,0,sizeof(map));
    17         while(n--){
    18             int a,b;
    19             cin>>a>>b;
    20             if(a>b) swap(a,b);
    21             for(int i=(a+1)/2;i<=(b+1)/2;i++) map[i]++;
    22         }
    23         int ans=0;
    24         for(int i=1;i<=maxn;i++) ans=max(ans,map[i]);
    25         cout<<ans*10<<endl;
    26     }
    27     return 0;
    28 }

    这个改了好久,还是WA。。。不知道为什么

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6  
     7 const int maxn=400;
     8 
     9 struct node{
    10     int l,r;
    11     bool operator<(const node& i)const{
    12         if(l==i.l) return r<i.r;
    13         return l<i.l;
    14     }
    15 }Room[maxn]; 
    16 
    17 int kase,n;
    18 bool vis[maxn];
    19 
    20 void Solve(){
    21     memset(vis,false,sizeof(vis));
    22     vis[1]=true;
    23     int ans=0,temp=1;
    24     while(true){ 
    25         for(int i=1;i<=n;i++){
    26             if(vis[i]) continue;
    27             if(Room[i].l-Room[temp].r>1) { vis[i]=true; temp=i; }
    28             if(Room[i].l-Room[temp].r==1){ 
    29                 if(Room[temp].l&1){ vis[i]=true; temp=i; }
    30             }     
    31         }
    32 
    33         ans++;
    34         int cnt=0;
    35         for(int i=1;i<=n;i++) if(!vis[i])
    36         {   temp=i;
    37             vis[i]=true;
    38             cnt++;
    39             break;
    40         }
    41         if(!cnt) break;
    42     }
    43     cout<<ans*10<<endl;
    44 }
    45 
    46 int main()
    47 {   cin>>kase;
    48     while(kase--){
    49         cin>>n;
    50         for(int i=1;i<=n;i++){
    51              scanf("%d%d",&Room[i].l,&Room[i].r);
    52              if(Room[i].l>Room[i].r)
    53                  swap(Room[i].l,Room[i].r);
    54         }
    55         sort(Room+1,Room+n+1);
    56         //for(int i=1;i<=n;i++) cout<<Room[i].l<<" "<<Room[i].r<<endl;
    57         Solve();
    58     }
    59     return 0;
    60 } 
  • 相关阅读:
    C/C++产生随机数
    BNUOJ34973Liserious战队
    oracle ebs 12.20 安装成功其过程失败日记及总结(1)
    HDU 2544 最短路 SPFA 邻接表 模板
    GridView编辑删除操作
    Hibernate_10_继承的例子_单表
    String不变性
    Mac在结构quick cocos2d-x编译环境
    Hash散列算法 Time33算法
    南京地图南京全套的卫星地图下载 百度高清卫星地图包括道路、标签信息叠加
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/7607524.html
Copyright © 2020-2023  润新知