hdu 1050

来源:互联网 发布:ubuntu翻译软件 编辑:程序博客网 时间:2024/06/04 18:39

题目链接 http://acm.hdu.edu.cn/data/images/1050-1.gif

题目大意:将桌子从房间i移动到房间j,要求如果两个桌子移动的路径分别为【x1,x2】[y1,y2]则这两个区间不能有重叠的部分

图转自贪心算法——Hdu 1050 Moving Tables


找线段重叠次数最多那一段

#include <stdio.h>#include <memory.h>int main(){    //freopen("in.txt", "r", stdin);    int r[200];    int T;    scanf("%d", &T);    while (T--){        memset(r, 0, sizeof(r));        int count,s,t;        scanf("%d", &count);         while (count--){            scanf("%d %d", &s, &t);            if (s > t){                int temp = s;                s = t;                t = temp;            }            if(s%2)s = (s - 1) / 2;            else s = (s - 2) / 2;            if (t % 2)t = (t - 1) / 2;            else t = (t - 2) / 2;            for (int i = s; i <= t; ++i){                r[i]++;            }        }        int ans = 0;        for (int i = 0; i <200; ++i){            if (ans < r[i])ans = r[i];        }        printf("%d\n", ans*10);    }    return 0;}


0 0
原创粉丝点击