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
- 자료구조
- 스택
- ue5
- 시뮬레이션
- XR Interaction Toolkit
- 그리디 알고리즘
- 투 포인터
- 다이나믹 프로그래밍
- Unreal Engine 5
- 트리
- 브루트포스
- 정렬
- 구현
- 문자열
- BFS
- 재귀
- 수학
- 유니티
- Team Fortress 2
- 우선순위 큐
- c++
- 누적 합
- VR
- 백준
- 백트래킹
- 다익스트라
- DFS
- 유니온 파인드
- 알고리즘
- 그래프
Archives
- Today
- Total
1일1알
백준 3495번 아스키 도형 C++ 본문
https://www.acmicpc.net/problem/3495
3495번: 아스키 도형
창영이는 메모장에 '.', '\', '/'을 이용해서 도형을 그렸다. 각 문자는 그림에서 1*1크기의 단위 정사각형을 나타낸다. '.'은 빈 칸을 나타내며, '/'는 정사각형의 왼쪽 아래 꼭짓점과 오른쪽 위 꼭짓
www.acmicpc.net
그래픽스 시간에 배운 홀수 규칙(Odd Parity Rule)을 이용해서 쉽게 풀었다.
각 높이마다 가로로 선을 그어서 ' . '을 만났을 때 이전에 만났던 ' / '나 ' \ ' 가 홀수개이면 안에 있는 것이고 짝수개이면 밖에 있는 것이다.
#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 h, w;
vector<vector<char>> board;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> h >> w;
board = vector<vector<char>>(h, vector<char>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> board[i][j];
}
}
float ans = 0;
for (int i = 0; i < h; i++) {
int cnt = 0;
for (int j = 0; j < w; j++) {
if (board[i][j] == '.') {
if (cnt % 2 == 1) ans += 1;
}
else {
ans += 0.5;
cnt++;
}
}
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 13424번 비밀 모임 C++ (0) | 2022.11.25 |
---|---|
백준 10025번 게으른 백곰 C++ (0) | 2022.11.24 |
백준 15922번 아우으 우아으이야!! C++ (0) | 2022.11.22 |
백준 14395번 4연산 C++ (0) | 2022.11.21 |
백준 9011번 순서 C++ (0) | 2022.11.20 |