题目:
题解:
typedef struct {double radius;double x_center;double y_center;
} Solution;Solution* solutionCreate(double radius, double x_center, double y_center) {srand((unsigned)time(NULL));Solution *obj = (Solution *)malloc(sizeof(Solution));obj->radius = radius;obj->x_center = x_center;obj->y_center = y_center;return obj;
}double* solutionRandPoint(Solution* obj, int* retSize) {double u = (double)rand() / RAND_MAX;double theta = (double)rand() / RAND_MAX * 2 * M_PI;double r = sqrt(u);double *res = (double *)malloc(sizeof(double) * 2);res[0] = obj->x_center + r * cos(theta) * obj->radius;res[1] = obj->y_center + r * sin(theta) * obj->radius;*retSize = 2;return res;
}void solutionFree(Solution* obj) {free(obj);
}