Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 그리디 알고리즘
- 문자열
- 재귀
- XR Interaction Toolkit
- 다익스트라
- 백트래킹
- 스택
- 다이나믹 프로그래밍
- 그래프
- BFS
- ue5
- 시뮬레이션
- 구현
- 투 포인터
- Unreal Engine 5
- 수학
- 백준
- 자료구조
- 누적 합
- 정렬
- VR
- 브루트포스
- 우선순위 큐
- DFS
- Team Fortress 2
- 트리
- 알고리즘
- 유니티
- c++
- 유니온 파인드
Archives
- Today
- Total
1일1알
백준 10703번 유성 C++ 본문
https://www.acmicpc.net/problem/10703
10703번: 유성
작고 특이한 모양의 유성 사진이 인터넷에 올라왔다. 사진에는 매우 높은 곳에서 떨어지고 있는 유성이 허공에 찍혀 있었다. 유성이 떨어지고 난 뒤의 사진도 있었지만 안타깝게도 소실돼버려
www.acmicpc.net
유성과 땅의 거리중 최소값을 찾아서 그만큼 밑으로 이동시켰다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int r, s;
vector<pair<int, int>> stars;
vector<int> starHeights;
vector<int> groundHeights;
vector<vector<char>> board;
const int BIGVALUE = 987654321;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> s;
starHeights = vector<int>(s, -1);
groundHeights = vector<int>(s, BIGVALUE);
board = vector<vector<char>>(r, vector<char>(s));
for (int i = 0; i < r; i++) {
for (int j = 0; j < s; j++) {
cin >> board[i][j];
if (board[i][j] == 'X') {
stars.push_back({ i,j });
starHeights[j] = i;
board[i][j] = '.';
}
else if (board[i][j] == '#') {
groundHeights[j] = min(groundHeights[j], i);
}
}
}
int down = BIGVALUE;
for (int i = 0; i < s; i++) {
int starHeight = starHeights[i];
int groundHeight = groundHeights[i];
if (starHeight == -1) continue;
if (groundHeight == BIGVALUE) continue;
down = min(down, groundHeight - starHeight - 1);
}
if (down != BIGVALUE) {
for (auto a : stars) {
board[a.first + down][a.second] = 'X';
}
}
for (auto a : board) {
for (auto b : a) {
cout << b;
}
cout << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 13022번 늑대와 올바른 단어 C++ (0) | 2022.11.29 |
---|---|
백준 22252번 정보 상인 호석 C++ (0) | 2022.11.27 |
백준 13424번 비밀 모임 C++ (0) | 2022.11.25 |
백준 10025번 게으른 백곰 C++ (0) | 2022.11.24 |
백준 3495번 아스키 도형 C++ (0) | 2022.11.23 |