HDU 1050(贪心)

题意:有一个走廊,走廊上下都有一排房间,从一个房间移动桌子到另一个房间要花费10分钟,走廊只够一个桌子移动,如果路径不重叠,则可以同时移动,求要花费的时间。

 

#include <cstdio>
#include <cstdlib>

int main()
{
    int T, n;
    int a, b, c[200];
    int i, j, temp, max;
    scanf("%d", &T);
    while (T--)
    {
        for (i = 0; i < 200; ++i)
            c[i] = 0;
        scanf("%d", &n);
        for (i = 1; i <= n; ++i)
        {
            scanf("%d %d", &a, &b);
            a = (a-1)/2;
            b = (b-1)/2;
            if (a > b)
                a ^= b ^= a ^= b;
            for (j = a; j <= b; ++j)
                ++c[j];
        }
        max = 0;
        for (i = 1; i < 200; ++i)
            if (c[i] > max)
                max = c[i];
        printf("%d\n", max * 10);
    }
}


 

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

struct Table
{
    int s, t, v;
    bool operator <(const Table& rhs) const
    {
        return s < rhs.s;
    }
} table[200];

int main()
{
    int T, n, a, b, N, sum, i;
    while (scanf("%d", &T) != EOF)
    {
        while (T--)
        {
            scanf("%d", &n);
            N = n;
            sum = 0;
            while (n--)
            {
                scanf("%d%d", &a, &b);
                a = (a-1)/2, b = (b-1)/2;
                if (a > b)
                    a ^= b ^= a ^= b;
                table[n].s = a, table[n].t = b, table[n].v = 0;
            }
            sort(table, table + N);
            int have_visit = 0;
            while (have_visit < N)
            {
                int first_no_visit = -1;
                for (i = 0; i < N; ++i)
                    if (table[i].v == 0)
                    {
                        ++have_visit;
                        first_no_visit = i;
                        table[i].v = 1;
                        break;
                    }
                    while (++i < N)
                    {
                        if (table[i].v == 0 && table[i].s > table[first_no_visit].t)
                        {
                            ++have_visit;
                            table[i].v = 1;
                            first_no_visit = i;
                        }
                    }
                    ++sum;
            }
            printf("%d\n", 10 * sum);        
        }
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值