20 Aug 2021
#include <iostream>
using namespace std;
int pro1[101][101];
int pro2[101][101];
int res[101][101];
int main()
{
int N, M, K;
cin >> N >> M;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin>>pro1[i][j];
}
}
cin >> M >> K;
for (int i = 0; i < M; i++) {
for (int j = 0; j < K; j++) {
cin >> pro2[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
for (int k = 0; k < M; k++) {
res[i][j] += pro1[i][k] * pro2[k][j];
}
cout << res[i][j] << " ";
}
cout << endl;
}
}
19 Aug 2021
절댓값 힙!
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int N, x;
priority_queue<int,vector<int>,greater<int>> pq1;
priority_queue<int> pq2;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> x;
if (x == 0)
if (pq1.empty() && pq2.empty()) cout << "0\n";
else {
if (pq1.empty()) {
cout << pq2.top() << '\n';
pq2.pop();
}
else if (pq2.empty()) {
cout << pq1.top() << '\n';
pq1.pop();
}
else {
if (pq1.top() < -pq2.top()) {
cout << pq1.top() << '\n';
pq1.pop();
}
else {
cout << pq2.top() << '\n';
pq2.pop();
}
}
}
}
else if (x > 0) pq1.push(x);
else pq2.push(x);
}
}
17 Aug 2021
너무 어려운 그래프… 언제쯤 우리 친해질 수 있을까…?
#include <iostream>
using namespace std;
int N, M;
char map[101][101];
bool visit[101][101];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int ans = 10001;
void dfs(int x, int y, int depth) {
if (x<0 || y<0 || x>=N || y>=M) return;
if (x==N-1 && y==M-1) {
if (depth < ans) ans = depth;
return;
}
for (int i=0; i<4; i++){
int xa = x+dx[i];
int ya = y+dy[i];
if (!visit[xa][ya] && map[xa][ya] == '1') {
visit[xa][ya] = true;
dfs(xa, ya, depth+1);
visit[xa][ya] = false;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
scanf("%d %d", &N, &M);
for (int i=0; i<N; i++) scanf("%s", map[i]);
dfs(0, 0, 1);
printf("%d\n", ans);
}

13 Aug 2021
min_heap 를 이용한 문제,,, 사실 구글링을 먼저했더니 헉했다… 이렇게 쉬운건가? 싶을 정도로 너무 잘 해두신 분들이 많아서, 이번에도 보고 배웠다 😱😂 switch도 오랜만에 보고, 큐 안에 저렇게 다양하게 벡터까지 넣어본 적도 처음… priority_queue 는 학교에서 직접 구현해서 써보기나 했지… 가져다가는 처음 써보는데, 역시…라이브러리가 좋구나~
#include <functional>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
priority_queue<int, vector<int>, greater<int> > pq;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int N;
scanf("%d", &N);
for (int i=0; i<N; i++) {
int x;
cin >> x;
if (x!=0) pq.push(x);
else {
if (!pq.empty()) {
cout << pq.top() << endl;
pq.pop();
}
else cout << 0 << endl;
}
}
return 0;
}
12 Aug 2021
🍅BFS🍅 문제인데, 개념은 아는데 코드로 구현하는게 헷갈려서 Geeks for Geeks와 구글링을 참고했다… 아니 정말 난 왜 이렇게 멍청한거냐…
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
pair<int, int> p;
queue<pair<int, int>> q;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0 , -1 };
int n, m, result = 0;
int graph[1001][1001];
bool inside(int ny, int nx) {
return (0 <= nx && 0 <= ny && nx < m && ny < n);
}
void bfs(void) {
while (!q.empty()) {
int y = q.front().first;
int x = q.front().second;
q.pop();
for (int i=0; i<4; i++) {
int ny = y + dy[i];
int nx = x + dx[i];
if (inside(ny,nx) && graph[ny][nx] == 0) {
graph[ny][nx] = graph[y][x] + 1;
pair<int, int> temp = make_pair(ny, nx);
q.push(temp);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int m,n;
cin >> m >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> graph[i][j];
if (graph[i][j] == 1) {
pair<int, int> temp = make_pair(i,j);
q.push(temp);
}
}
}
bfs();
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (graph[i][j] == 0) {
cout << "-1" << endl;
return 0;
}
if (result < graph[i][j]) {
result = graph[i][j];
}
}
}
cout << result-1 << endl;
return 0;
}
오늘의 TMI
- GitHub Repo에 들어간다
- Repo 화면에서
. 키를 누른다
- Online VSCode Editor를 통해 코드 수정이 가능하다
LinkedIn에서 이 글을 계속 봤었는데, 저게 뭐지(?) 하면서 핸드폰 보다가 집에 와서 해보니 이게 된다…!!!😱✨ 너무 신기해… 가끔 귀찮을 때는 GitHub Web에서 코드 수정하는 경우가 많았는데, 이렇게 편하게 수정할 수 있다니 너무 신기한 것…..!!! 어쨌든 Online GitHub VS Code Editor로 써보는 첫 블로그 글! 안녕 👍🏼😎👋🏼👋🏼