leetcode-每日一题-3025. 人员站位的方案数 I-C语言

  • 输入:
    2 <= n <= 50
    points[i].length == 2
    0 <= points[i][0], points[i][1] <= 50
    points[i] 点对两两不同。
c 复制代码
// 按x降序,按y升序
int cmp(const void *a, const void *b) {
    int *p = *(int **)a;
    int *q = *(int **)b;
    if(p[0] == q[0]){
        return p[1]-q[1];
    } 
    else return q[0]-p[0];
}
// 判断c点是否在a为右下角,b为左上角的矩形和边界内
bool IsPad(int *pointa, int *pointb, int *pointc) {
    return !(pointc[0] > pointa[0] || pointc[0] < pointb[0] || pointc[1] < pointa[1] || pointc[1] > pointb[1]);
}
int numberOfPairs(int** points, int pointsSize, int* pointsColSize) {
    int res = 0;
    qsort(points, pointsSize, sizeof(int *), cmp);
    for(int i=0; i<pointsSize; i++) {
        for(int j=i+1; j<pointsSize; j++) {
            if(points[j][1] < points[i][1]){
                continue;
            }
            int k=i+1;
            while(k<j) {
                if(IsPad(points[i], points[j], points[k])) break;
                k++;
            }
            if(k == j) res++;
        }
    }
    return res;
}
相关推荐
2401_841495641 天前
【计算机视觉】基于复杂环境下的车牌识别
人工智能·python·算法·计算机视觉·去噪·车牌识别·字符识别
Jonkin-Ma1 天前
每日算法(1)之单链表
算法
奔跑吧邓邓子1 天前
【C语言实战(8)】C语言循环结构(do-while):解锁编程新境界
c语言·实战·do-while
晚风残1 天前
【C++ Primer】第六章:函数
开发语言·c++·算法·c++ primer
小莞尔1 天前
【51单片机】【protues仿真】基于51单片机温度测量系统
c语言·单片机·嵌入式硬件·物联网·51单片机
杨云强1 天前
离散积分,相同表达式数组和公式
算法
地平线开发者1 天前
征程 6 | BPU trace 简介与实操
算法·自动驾驶
满天星83035771 天前
【C++】AVL树的模拟实现
开发语言·c++·算法·stl
晓风凌殇1 天前
单片机按键检测与长短按识别实现
c语言·单片机
Lris-KK1 天前
力扣Hot100--94.二叉树的中序遍历、144.二叉树的前序遍历、145.二叉树的后序遍历
python·算法·leetcode