hdu1050

7 篇文章 0 订阅

题意:在一个走廊里面移桌子,但是走廊很窄,一次只能通过一把椅子。

如果移动的路线没有相交,可以同时进行。问你最少的时间是多少?

思路:可以将房间移到同一边,即(1,2)(3,4)(5,6)。。。。将这两个相对的房间变成同一个房间,然后用一个数组去存储每一个房间被经过的次数,最大值就是最少的时间。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 205
using namespace std;

int main()
{
    int t,n;
    int cnt[N];
    scanf("%d",&t);
    while(t--)
    {
        memset(cnt,0,sizeof(cnt));
        scanf("%d",&n);
         int maxn=-1,from,to;
         while(n--)
         {
             scanf("%d%d",&from,&to);
             if(from>to)
                swap(from,to);
             from=(from+1)/2;
             to=(to+1)/2;
             for(int i=from;i<=to;i++){
                cnt[i]++;//从from~to沿途经过的点都加一次
                if(cnt[i]>maxn)
                    maxn=cnt[i];
             }
         }
         printf("%d\n",maxn*10);
        }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值