• 【leetcode】供暖器


    #define MAX(a,b) ((a)>(b)?(a):(b))
    #define MIN(a,b) ((a)<(b)?(a):(b))
    
    int cmp(const void* a,const void* b){
        return *(int*)a > *(int*)b;
    }
    int findRadius(int* houses, int housesSize, int* heaters, int heatersSize){
        int i=0,j=0,radius=1000000001,min,minRadius=0;
        qsort(houses,housesSize,sizeof(int),cmp);
        qsort(heaters,heatersSize,sizeof(int),cmp);
    
        while(i<housesSize && j<heatersSize)
        {        
            min = (j>0)? MIN(abs(heaters[j]-houses[i]),abs(heaters[j-1]-houses[i])): abs(heaters[j]-houses[i]);
            if (min < radius) radius=min;
            if (houses[i] <= heaters[j])
            {        
                if (houses[i]==heaters[j])
                    j++;
                if (min > minRadius) minRadius=min;
                i++;
                radius=1000000001;
            }
            else
                j++;
        }
        if (j==heatersSize && i!=housesSize && houses[housesSize-1] - heaters[j-1] > minRadius)
            minRadius=houses[housesSize-1] - heaters[j-1];
    
        return minRadius;
    }
  • 相关阅读:
    js中Frame框架的属性获取(1)
    c#中文件上传(1)
    表单验证Validform
    Mybatis语法笔记
    js的checkbox
    调用微信Js-SDK支付
    调用微信Js-SDK图片
    java后台上传到linux
    web服务器内层溢出
    SpringMVC
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13735734.html
Copyright © 2020-2023  润新知