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 |
Tags
- VR
- ue5
- 백준
- 시뮬레이션
- XR Interaction Toolkit
- 유니온 파인드
- 구현
- 정렬
- 알고리즘
- 다이나믹 프로그래밍
- DFS
- 그리디 알고리즘
- Unreal Engine 5
- 우선순위 큐
- 유니티
- c++
- 수학
- 다익스트라
- 투 포인터
- 재귀
- 누적 합
- 백트래킹
- 트리
- 그래프
- 자료구조
- 스택
- 브루트포스
- BFS
- Team Fortress 2
- 문자열
Archives
- Today
- Total
1일1알
백준 9518번 로마 카톨릭 미사 C++ 본문
https://www.acmicpc.net/problem/9518
9518번: 로마 카톨릭 미사
로마 카톨릭 미사에서 가장 멋진 부분은 사람들이 서로 악수를 하면서 "평화가 함께하기를" 이라고 말하는 평화 의식이다. 성당에는 R개의 벤치가 한 행에 하나씩 있고, 각 벤치에는 총 S명이 앉
www.acmicpc.net
빈 자리에 하나씩 배치하면서 악수한 횟수를 구했다. 그리고 1번과 2번이 악수한것과 2번과 1번이 악수한것은 같기 때문에 구한 횟수에서 2를 나눴다. 이렇게 구한 수들 중 가장 큰 수를 찾았다.
#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 dRow[8] = { -1,-1, 0, 1, 1, 1, 0,-1 };
int dCol[8] = { 0, 1, 1, 1, 0,-1,-1,-1 };
int r, s;
vector<vector<bool>> filled;
vector<pair<int, int>> sg;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> r >> s;
filled = vector<vector<bool>>(r, vector<bool>(s, false));
for (int i = 0; i < r; i++) {
string str;
cin >> str;
for (int j = 0; j < s; j++) {
if (str[j] == 'o') filled[i][j] = true;
else sg.push_back({ i,j });
}
}
if (sg.empty()) sg.push_back({ 0,0 });
int ans = 0;
for (auto curr : sg) {
filled[curr.first][curr.second] = true;
set<pair<int,int>> handShakes;
int cnt = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < s; j++) {
if (filled[i][j] == false) continue;
for (int k = 0; k < 8; k++) {
int nextRow = i + dRow[k];
int nextCol = j + dCol[k];
if (nextRow < 0 || nextRow >= r) continue;
if (nextCol < 0 || nextCol >= s) continue;
if (filled[nextRow][nextCol] == false) continue;
cnt++;
}
}
}
ans = max(ans, cnt / 2);
filled[curr.first][curr.second] = false;
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 11504번 돌려 돌려 돌림판! C++ (0) | 2023.04.06 |
---|---|
백준 15787번 기차가 어둠을 헤치고 은하수를 C++ (0) | 2023.04.05 |
백준 11578번 팀원 모집 C++ (0) | 2023.03.30 |
백준 1461번 도서관 C++ (0) | 2023.03.26 |
백준 17213번 과일 서리 C++ (0) | 2023.03.24 |