일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 30 |
Tags
- EOI
- 프로그래머스
- 온라인석사
- 주정부이민
- MATLAB
- mpnp
- 코딩테스트
- LAA
- 선형대수
- 매트랩
- 컴퓨터과학과
- 조지아텍
- 캐나다 영주권
- omscs
- LV1
- cpp
- 알고리즘
- leetcode
- zeros
- 방송통신대학교
- Deep learning
- 개발자
- 방통대
- 딥러닝
- Plotting
- 머신러닝
- 기본
- 마니토바
- machine learning
- C++
Archives
- Today
- Total
Krononberg
1030. Matrix Cells in Distance Order.cpp 본문
⭐ discussion에서 배운 것, 두 가지.
res.push_back({d,d,d,d,d,d,d,d});
sort(res.begin(), res.end(), []vector<int>a,vector<int>b);
//multimap 나의 풀이
class Solution {
public:
vector<vector<int>>res;
vector<vector<int>> allCellsDistOrder(int rows, int cols, int rCenter, int cCenter) {
multimap<int,vector<int>>m;
for(int i =0; i<rows; i++){
for(int j =0; j<cols; j++){
vector<int>tmp;
tmp.push_back(i);
tmp.push_back(j);
m.insert(pair<int,vector<int>>(abs(rCenter-i)+abs(cCenter-j),tmp));
}
}
for(auto it : m){
res.push_back(it.second);
}
return res;
}
};
//discusstion 풀이
class Solution {
public:
vector<vector<int>> allCellsDistOrder(int R, int C, int r0, int c0) {
vector<vector<int>> ans;
for (int i = 0; i < R; i++)
for (int j = 0; j < C; j++)
ans.push_back({i, j, abs(i - r0) + abs(j - c0)});
sort(ans.begin(), ans.end(), [](vector<int>& c1, vector<int>& c2) {
return c1[2] < c2[2];
});
for (vector<int>& d: ans)
d.pop_back();
return ans;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1636. Sort Array by Increasing Frequency.cpp (0) | 2021.11.20 |
---|---|
1002. Find Common Characters.cpp (0) | 2021.11.19 |
821. Shortest Distance to a Character.cpp (0) | 2021.11.16 |
1356. Sort Integers by The Number of 1 Bits.cpp (0) | 2021.11.07 |
1337. The K Weakest Rows in a Matrix.cpp (0) | 2021.10.30 |