贪心 000 关于运送木板的问题

本文介绍了一种解决办公室内桌子搬运问题的算法。通过设定合理的数据结构和比较函数,算法能够有效计算出同时进行多个桌子搬运任务时所需的最大时间,确保走廊利用率最大化,从而提高搬运效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<h1>Problem A </h1><h5>Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)</h5><h5>Total Submission(s) : 349   Accepted Submission(s) : 46</h5><div class="panel_title" align="left">Problem Description</div><div class="panel_content">The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. 

<center><img style="MAX-WIDTH: 100%" src="http://acm.hdu.edu.cn/data/images/1050-1.gif" alt="" /></center>

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. 

<center><img style="MAX-WIDTH: 100%" src="http://acm.hdu.edu.cn/data/images/1050-2.gif" alt="" /></center>

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.
</div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Input</div><div class="panel_content">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. </div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Output</div><div class="panel_content">The output should contain the minimum time in minutes to complete the moving, one per line. </div><div class="panel_bottom"> </div>
<div class="panel_title" align="left">Sample Input</div><div class="panel_content"><pre><div style="FONT-FAMILY: Courier New,Courier,monospace">3 
4 
10 20 
30 40 
50 60 
70 80 
2 
1 3 
2 200 
3 
10 100 
20 80 
30 50 
</div>
 

Sample Output
10 20 30


木板运送的问题
设立数组
求重叠部分
重叠加一
知道最后求数组中最大的数。


#include<iostream>
#include<string.h>
#include<set>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<string>
using namespace std;
struct hh
{
    int k;
    int l;
};
bool comp(const hh &A,const hh &B)
{
     if(A.k!=B.k)
      return A.l<B.l;
      else
      return  A.k<B.k;
}
int main()
{
    int n;
    cin>>n;
    int i;
    vector<hh> s;
    hh w;
    int t,x1,x2,x3;
    for(i=1;i<=n;i++)
        { cin>>t;
           for( x1=1;x1<=t;x1++)
           {
               cin>>w.k;
               cin>>w.l;
               if(w.k>w.l)
               {
                   swap(w.k,w.l);
               }
               s.push_back(w);
           }

           int a[200];
           memset(a,0,sizeof(a));
           int e;
           int oo;
           for(e=0;e<t;e++)
           {
               for(oo=(s[e].k-1)/2;oo<=(s[e].l-1)/2;oo++)
               {
                   a[oo]++;
                            }
           }
           int mix;
           mix=a[0];
           int ss;
           for(ss=0;ss<200;ss++)
           {
               if(mix<a[ss])
               mix=a[ss];
           }

           cout<<mix*10<<endl;
           s.clear();
        }
        return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值