# 356. 直线镜像

bool isReflected(int** points, int pointsSize, int* pointsColSize){
    int i, j;
    for(i = 0; i<pointsSize-1; i++)
    {
        for(j = i+1; j<pointsSize; j++)
        {
            if(points[j][0] < points[i][0])
            {
                int *tmp = points[i];
                points[i] = points[j];
                points[j] = tmp;
            }
        }
    }
    float line  = (points[0][0] + points[pointsSize-1][0]) / 2.;
    i = 0, j = pointsSize-1; 
    while(i < pointsSize && points[i][0] < line) i++;
    while(j >= 0 && points[j][0] > line) j--;
    if(i == 0 && j == pointsSize-1) return true;
    i--, j++;
    int left = i, right = j;
    bool *flag = (bool *)malloc(sizeof(bool) * pointsSize);
    memset(flag, false, sizeof(bool) * pointsSize);
    while(left >= 0)
    {
        right = j;
        while(right < pointsSize)
        {
            if((points[left][0] + points[right][0] == 2*line) && points[left][1] == points[right][1])
            {
                flag[left] = true;
                flag[right] = true;
                break; 
            }
            right++;
        }
        if(right == pointsSize) return false;
        left--;
    }
    right = j;
    while(right < pointsSize)
    {
        if(flag[right])
        {
            right++;
            continue;
        }
        left = i;
        while(left >= 0)
        {
            if((points[left][0] + points[right][0] == 2*line) && points[right][1] == points[left][1]) break;
            left--;
        }
        if(left < 0) return false;
        right++;
    }
    return true;
}

上一篇:初识线性回归~


下一篇:ros自定义.srv服务数据,以及服务器的使用