Help! Why no working for the last 3 case? (Resolved: count the total pts inside each rec not area)
Now I understand. In order to solve this problem, we assume that the proportion is on the number of total points each rectangle not the area.\nThe difference is
Now I understand. In order to solve this problem, we assume that the proportion is on the number of total points each rectangle not the area.\nThe difference is as follows\nAssume the rectangle is [x1, y1, x2, y2] where (x1,y1) the bottom left corner and (x2,y2) the top right corner\nThe area of the rectangle is (x2 - x1) * (y2 - y1) while the total points are (x2 - x1 + 1) * (y2 - y1 + 1)\n\n\n```\nfrom bisect import bisect_left\nfrom random import randint\n\nclass Solution:\n\n    def __init__(self, rects: List[List[int]]):\n        self.res = []\n        self.tot = 0\n        self.dic = {}\n        for a, b, c, d in rects:\n            area = (c - a + 1) * (d - b + 1)\n            self.tot += area\n            self.res.append(self.tot)\n            self.dic[self.tot] = [a, b, c, d]\n\n    def pick(self) -> List[int]:\n        random = randint(1, self.tot)\n        idx = bisect_left(self.res, random)\n        a, b, c, d = self.dic[self.res[idx]]\n        return [randint(a, c), randint(b, d)]\n\n\n```\n------------------------------------------------------------------------\n\nI did the picking proportionally to the area. I tried several ways. One way is by randint, oneway is using choices with weight function of individual weight. None is working...Please help!\n\n"""\nfrom bisect import bisect\nfrom random import randint\n\nclass Solution:\n\n    def __init__(self, rects: List[List[int]]):\n        self.x = [[a, c] for a,b,c,d in rects]\n        self.y = [[b, d] for a,b,c,d in rects]\n        sa, self.area = 0, []\n        for a,b,c,d in rects:\n            sa +=  (d -b) * (c - a)\n            self.area.append(sa)\n        \n\n    def pick(self) -> List[int]:\n        idx = bisect(self.area, randint(1, self.area[-1])) - 1\n        x1,x2 = self.x[idx]\n        y1,y2 = self.y[idx]\n        return randint(x1, x2), randint(y1,y2)\n"""\n
['Python3']