HDU-1050 Moving Tables 贪心

来源:互联网 发布:龙江网络佳木斯分公司 编辑:程序博客网 时间:2024/05/22 06:44

解题思路:
 将走廊按1-200进行编号,计算每一段走廊重叠使用次数,重叠次数最大值*10即为所需时间。

关键点:
走廊号 = (房间号 + 1) / 2

注意点:
判断移动房间号的大小 ( 从房间号较小的房间移到较大的房间 )

#include<iostream>#include<iomanip>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){#ifndef ONLINE_JUDGE    freopen("1050in.txt","r",stdin);#endif    int n, i, a[205];    int s, t;    int caseNum;    cin>>caseNum;    while(caseNum--)    {        memset(a, 0, sizeof(a));        cin>>n;        while(n--)        {            cin>>s>>t;            if(s > t)//判断房间号大小            {                swap(s, t);            }            for(i = (s+1)/2; i <= (t+1)/2; i++)//标记走廊号            {                a[i]++;            }        }        int time = 0;        for(i = 1; i <= 200; i++)        {            time = max(time, a[i]);//取得走廊重叠最大次数        }        cout<<time*10<<endl;    }    return 0;}
0 0
原创粉丝点击