3143. 正方形中的最多点数
题目链接:3143. 正方形中的最多点数
代码如下:
//参考链接:https://leetcode.cn/problems/maximum-points-inside-the-square/solutions/2775310/er-fen-bian-chang-tong-shi-ji-lu-da-an-z-92w5
class Solution
{
public:
int maxPointsInsideSquare(vector<vector<int>>& points, string s)
{
int res = 0;
function<bool(int)> check = [&](int size)->bool
{
int vis = 0;
for (int i = 0; i < points.size(); i++)
{
//判断点是否在正方形中
if (abs(points[i][0]) <= size && abs(points[i][1]) <= size)
{
char c = s[i] - 'a';
if (vis >> c & 1) { return false; }
vis |= 1 << c;// 把 c 加入集合
}
}
res = __builtin_popcount(vis);
return true;
};
int left = -1, right = 1'000'000'001;
while (left + 1 < right)
{
int mid = (left + right) / 2;
(check(mid) ? left : right) = mid;
}
return res;
}
};
标签:vis,int,mid,正方形,3143,点数,points
From: https://blog.csdn.net/weixin_45256307/article/details/141052151