ZOJ1029

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=29

既然有重合的地方,那重合的地方只能一次次地搬嘛,所以一开始是想先排序,然后模拟搬桌子,看搬多少次,但心里没底,所以干脆看了答案。

答案上是先让所有的桌子走一遍,记录走廊的每一个位置各走过多少次,最多的那个乘以10就是结果。

#include<iostream>
#include<memory.h>
using namespace std;

int Time[210];

int main()
{
    int T;

    cin>>T;
    while (T--)
    {
        memset(Time,0,sizeof(Time));
        int N, s, t;
        cin>>N;
        for (int i=0; i<N; i++)
        {
            cin>>s>>t;
            if (s % 2)
                s = (s+1)/2;
            else
                s /= 2;
            if (t % 2)
                t = (t+1)/2;
            else
                t /= 2;
            if (s > t)
            {
                int tmp = s;
                s = t;
                t = tmp;
            }
            for (int j=s; j<=t; j++)
                Time[j]++;
        }
        int MAX = 0;
        for (int j=1; j<=200; j++)
            MAX = Time[j] > MAX ? Time[j] : MAX;
        cout<<MAX*10<<endl;
    }

    return 0;
}


你可能感兴趣的:(ZOJ1029)