hdu acm-step 1.3.1 Moving Tables

          本题题意是:有一个走廊以及200组互相对着的房间,现在要在不同的房间之间送信,但走廊一次只能通过一个人,因此一旦两个人的路线有重复的部分,那么

          就只能分两批走,送一次信要10分钟,现在给出n个人送信的路线,求他们所花的最少时间。

          代码如下:

          

#include <cstdio>

using namespace std;

int main()
{

    int T;

    scanf("%d",&T);

    while(T--)
    {

        int a[201] = {0};

        int n;

        scanf("%d",&n);

        int l,r;

        for(int i=0;i<n;i++)
        {

            scanf("%d%d",&l,&r);        

            l = (l + 1) / 2;

            r = (r + 1) / 2;

            if(l > r)
            {

                int t = l;

                l = r;

                r = t;

            }

            for(int i=l;i<=r;i++)
            {

                a[i]++;        

            }            

        }

        int max = 0; 

        for(int i=1;i<=200;i++)

            max = max > a[i] ? max : a[i];        

        printf("%d\n",max*10);

    }

    return 0;

}

其实仔细想想就会发现每两个相对的房间可以划分为1个区域,这样400个房间就能划分为200个区域。

然后再分析路线相交的情况有三种:"完全不相交,部分相交,重合"。

又发现三个人如果不是三人的路线都有重合,那么它们的时间是20。

仔细推理就可以发现只需要求每个人房间经过的人数,然后取其中最大值便是最短时间,因为总有m个人通过该房间,无论怎么调度,这m次是无法避免的。

我们只需要用数组模拟房间经过的人数,然后取最大值,便得到了结果。

需要注意的是,大编号房间到小编号房间时,注意交换两者的序号,否则for循环不会执行(TAT,之前还以为自己写错了,但怎么看逻辑都是对的)。

时间: 2024-08-08 09:38:17

hdu acm-step 1.3.1 Moving Tables的相关文章

HDU 1050 Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23044    Accepted Submission(s): 7749 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

HDU 1050 Moving Tables (贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20302    Accepted Submission(s): 6889 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

hdu 1.3.1 Moving Tables

这道题比较简单,就是用数组存取其路径.如101和102是对门,其过道号可以记为51.  1和2之间的为1. 今早突然收到操作系统停课的通知,哈哈 回来就做一下水题,开心 1 #include<cstdio> 2 #include<memory.h> 3 int main() 4 { 5 //freopen("input.txt","r",stdin); 6 int T,n,a,b; 7 int s[201]; 8 int max; 9 int

HDU 1050.Moving Tables【细节与方法选取】【8月26】

Moving Tables Problem 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

杭电 1150 moving tables

http://acm.hdu.edu.cn/showproblem.php?pid=1050 Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18850    Accepted Submission(s): 6440 Problem Description The famous ACM (Advanced C

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

hdu1050&amp;&amp;nyoj220 Moving Tables(贪心)

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24372    Accepted Submission(s): 8071 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a

hdoj 1050 Moving Tables【贪心区间覆盖】

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 24316    Accepted Submission(s): 8053 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a b

HDU1050(Moving Tables:贪心算法)

解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可以得到结果. Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 28033    Accepted Submis

HDU1050:Moving Tables

Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19156    Accepted Submission(s): 6532 Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a