poj 1083

简介:

一、题目大意

一层里面有400个房间,北边和南边各有200个房间,要从一个房间里面把一张桌子移动到另一个房间(特别注意有可能有s比t大的情况,我因为这个WA了一次),需要占用这两个房间之间的所有走廊(包括这两个房间前面的),每移动一个桌子需要10分钟,给出需要移动的桌子的数据(从哪移动到哪),要求计算出最少需要多少分钟才能把所有桌子移动完。

另外注意:

房间1和2前面是同一个走廊,所以从1移动到2只需要占用一个走廊,房间2和3前面不是同一个走廊,因此从2移动到3需要占用2个走廊。

问题的关键是:
什么情况下移动不能同时进行?
比如3—5和4—6这里有重复要使用的4这个有什么用呢?而 10—20和30—40,这里没有重复的区间,可以同时进行移动。。想来想去他为什么要这么说,其实就是要告诉你去求覆盖区间最大的区域,所以acm重点在数学模型的抽象

二、AC code

分析:

本来是在dp专题里面找到的这题,很像贪心法,但是我硬是没想出如何用dp,倒是利用每条走廊都设置一个计数器,每经过一次+1,最大的次数X10就是答案。

#include <stdio.h>
#include <iostream>
#include <string.h>
#define MAXN 202

using namespace std;

int corridor[MAXN];

int main()
{
    //freopen("input.txt","r",stdin);

    int T;
    cin >> T;

    while(T--) {

        memset(corridor,0,sizeof(corridor));

        int N;
        cin>>N;

        int time = 0;
        for (int i = 0; i < N; ++i)
        {
            int s,t;
            cin>>s;
            cin>>t;

            if (s>t) {
                int tmp = s;
                s = t;
                t = tmp;
            }

            for (int j = (s%2 == 1)?(s+1)/2:s/2; j <= ( (t%2 == 1)?(t+1)/2:t/2 ); ++j)
                /* count time of the use of corridor */
                if ( time < ++corridor[j] )
                    time = corridor[j];
        }

        cout<<time*10<<endl;
    }

    return 0;
}
相关文章
|
3月前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
|
容器
POJ 3640 Conformity
POJ 3640 Conformity
48 0
poj 3620
题意:给出一个矩阵,其中有些格子干燥、有些潮湿。       如果一个潮湿的格子的相邻的四个方向有格子也是潮湿的,那么它们就可以构成更大       的湖泊,求最大的湖泊。       也就是求出最大的连在一块儿的潮湿的格子的数目。
563 0
POJ 1804
题目:http://poj.org/problem?id=1804 大意:给你一串数字,排序。求出最少的交换次数  \ 我用归并做的 #include #include using namespace std; int aa[500010],bb[500010]; long lon...
687 0
POJ-1003-hangover
Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length.
753 0
poj题目分类
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html
766 0