力扣 第 290 场周赛

2248. 多个数组求交集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {

public:
vector<int> intersection(vector<vector<int>>& nums) {
map<int,int> mp;
vector<int> ans;
int n=nums.size();
if(n==0) return ans;
for(int i=0;i<n;i++)
{
int m=nums[i].size();
for(int j=0;j<m;j++)
mp[nums[i][j]]++;
}
for(auto i:mp)
if(i.second==n) ans.push_back(i.first);
return ans;
}
};

2249. 统计圆内格点数目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {

public:
int countLatticePoints(vector<vector<int>>& circles) {
set<pair<int,int>> s;
int n=circles.size();
for(int i=0;i<n;i++)
{
int x=circles[i][0],y=circles[i][1],r=circles[i][2];
for(int xx=x-r;xx<=x+r;xx++)
for(int yy=y-r;yy<=y+r;yy++)
{
if((xx-x)*(xx-x)+(yy-y)*(yy-y)<=r*r) s.insert({xx,yy});
}
}
return s.size();
}

};

2250. 统计包含每个点的矩形数目

赛时疯狂tle,我觉得自己写的天衣无缝

自闭了

我也不知道我写错在哪了

毕竟这个题解已经咕咕咕半个月了

果然重构一次就ac

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
vector<int> re[101];
public:
vector<int> countRectangles(vector<vector<int>>& rectangles, vector<vector<int>>& points) {
vector<int> ans;

int n = rectangles.size();
for (int i = 0; i < n; i++)
re[rectangles[i][1]].push_back(rectangles[i][0]);
for (int i = 0; i < 101; i++)
sort(re[i].begin(), re[i].end() );

n = points.size();
for (int i = 0; i < n; i++)
{
int cnt = 0;
for (int j = points[i][1]; j <= 100; j++)
{
int l = re[j].size(), k = 0;
for (; k < l; k++)
if (re[j][k] >= points[i][0]) break;

cnt += l - k;
}
ans.push_back(cnt);
}
return ans;
}
};

2251. 花期内花的数目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
vector<int> st,en;
public:
vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& persons) {
vector<int>ans;
int n=flowers.size();
for(int i=0;i<n;i++)
st.push_back(flowers[i][0]),en.push_back(flowers[i][1]);
st.push_back(-1);
st.push_back(INT_MAX);
en.push_back(-1);
en.push_back(INT_MAX);
sort(st.begin(),st.end());
sort(en.begin(),en.end());
n=persons.size();
for(int i=0;i<n;i++)
{
int l=upper_bound(st.begin(),st.end(),persons[i])-st.begin();
int r=lower_bound(en.begin(),en.end(),persons[i])-en.begin();
ans.push_back(l-r);
}

return ans;
}
};