# leetcode weekly-contest-290

### T1 多个数组求交集

输入：nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]

nums[0] = [3,1,2,4,5]，nums[1] = [1,2,3,4]，nums[2] = [3,4,5,6]，在 nums 中每个数组中都出现的数字是 3 和 4 ，所以返回 [3,4] 。

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> intersection(vector<vector<int>>& nums) {
map<int,int> mp;
for(auto n:nums){
for(auto num:n){
mp[num]++;
}
}
vector<int> ans;
for(auto i :mp){
if(i.second==nums.size()){
ans.push_back(i.first);
}
}
return ans;
}
};

int main(){
Solution s;
vector<vector<int>> mp={{3,1,2,4,5},{1,2,3,4},{3,4,5,6}};
vector<int> ans=s.intersection(mp);
for(auto i : ans){
cout<<i<<endl;
}
}

### T26042. 统计圆内格点数目

格点 是指整数坐标对应的点。

输入：circles = [[2,2,1]]

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
int countLatticePoints(vector<vector<int>>& circles) {
set<pair<int,int>> ans;
for(auto circle:circles){
int x=circle[0];
int y=circle[1];
int r=circle[2];
for(int nx=x-r;nx<=x+r;nx++){
for(int ny=y-r;ny<=y+r;ny++){
if((nx-x)*(nx-x)+(ny-y)*(ny-y)<=r*r){
ans.insert({nx,ny});
}
}
}
}
return ans.size();
}
};

int main(){
Solution s;
vector<vector<int>> mp={{2,1,1}};
cout<<s.countLatticePoints(mp);
}

### T3统计包含每个点的矩形数目

输入：rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> countRectangles(vector<vector<int>>& rectangles, vector<vector<int>>& points) {
vector<vector<int>> mp(101);
for(auto i:rectangles){
mp[i[1]].push_back(i[0]);
}
for(auto &i :mp){
sort(i.begin(),i.end());
}
vector<int> ans;
for(auto i : points){
int x=i[0],y=i[1];
int cnt=0;
for(int q =100;q>=y;q--){
if(mp[q].size()==0){
continue;
}
cnt+=mp[q].end()-lower_bound(mp[q].begin(),mp[q].end(),x);
}
ans.push_back(cnt);
}
return ans;
}
};

int main(){
Solution s;
vector<vector<int>> rectangles={{1,2},{2,3},{2,5}};
vector<vector<int>> points={{2,1},{1,4}};
vector<int>ans=s.countRectangles(rectangles,points);
for(auto i: ans){
cout<<i<<" ";
}
}

### T4花期内花的数目

输入：flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]

#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& persons) {
map<int,int> mp;
for(auto line : flowers){
mp[line[0]]++;
mp[line[1]+1]--;
}
vector<int> idx(persons.size());
for(int i = 0 ;i<persons.size();i++){
idx[i]=i;
}
sort(idx.begin(),idx.end(),[&](int a,int b){
return persons[a]<persons[b];
});
vector<int> ans(persons.size());
auto it=mp.begin();
int now=0;
for(int i =0 ; i<persons.size();i++){
while(it->first<=persons[idx[i]]&&it!=mp.end()){
now+=it->second;
it++;
}
ans[idx[i]]=now;
}
return ans;
}
};
int main(){
Solution s;
vector<vector<int>> flowers={{1,6},{3,7},{9,12},{4,13}};
vector<int> persons={2,3,7,11};
vector<int>ans=s.fullBloomFlowers(flowers,persons);
for(auto i: ans){
cout<<i<<" ";
}

}