hdu 1050

题目链接 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值