0
点赞
收藏
分享

微信扫一扫

Leecode 第 290 场周赛 6042. 统计圆内格点数目

芷兮离离 2022-04-24 阅读 29
c++leetcode

原题链接:Leecode 第 290 场周赛 6042. 统计圆内格点数目
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

class Solution {
public:
    int countLatticePoints(vector<vector<int>>& circles) {
        map<pair<int,int>,int> m;
        int n=circles.size();
        for(int i=0;i<n;i++)
        {
            int x=circles[i][0];
            int y=circles[i][1];
            int r=circles[i][2];
            int xl=x-r,xr=x+r,yu=y+r,yd=y-r;
            for(int j=xl;j<=xr;j++)
            {
                for(int k=yd;k<=yu;k++)
                {
                    int tmp=(j-x)*(j-x)+(k-y)*(k-y);
                    if(tmp<=r*r)  m[make_pair(j,k)]=1;
                }
            }
        }
        int res=m.size();
        return res;
    }
};
举报

相关推荐

LeetCode第290场周赛

力扣第290场周赛

第 291 场周赛

第 279 场周赛

第 286 场周赛

第287场周赛

第 276 场周赛

[Acwing] 第 49 场周赛

0 条评论