HDU 1050(贪心)

来源:互联网 发布:怎么淘宝联盟不能注册 编辑:程序博客网 时间:2024/06/07 10:14

题意:有一个走廊,走廊上下都有一排房间,从一个房间移动桌子到另一个房间要花费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;}


 

0 0
原创粉丝点击