You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
어쨌든 다각형이 몇각형인지 구하려면 꼭지점의 개수를 구해야 한다.
이건 에디토리얼을 참고했는데 상하좌우 2칸씩 개수를 세서 검은색 블록 (#)이 1개 또는 3개이면 꼭지점이다.
예시를 보면 좀 이해가 가긴 하는데
.....
.###.
.###.
.###.
.....
이건 4각형이고
.....
.#.#.
.###.
.###.
.....
이건 8각형이 된다
Source Code
#include<iostream>
#include<string>usingnamespacestd;intmain() {
int h, w;
cin >> h >> w;
string grid[10];
for (int i = 0; i < h; i++)
{
cin >> grid[i];
}
int ans = 0;
for (int i = 0; i < h - 1; i++)
{
for (int j = 0; j < w - 1; j++)
{
int cnt = 0;
for (int a = 0; a < 2; a++)
{
for (int b = 0; b < 2; b++)
{
cnt += (grid[i + a][j + b] == '#');
}
}
if (cnt == 1 || cnt == 3)
{
ans++;
}
}
}
cout << ans << endl;
}
This discussion was converted from issue #45 on September 15, 2026 10:47.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://atcoder.jp/contests/abc191/tasks/abc191_c
Problem Summary
그리드에
#,.으로 이루어진 문자열이 주어질 때 이 도형이 몇각형인지 구하는 문제.Solution
문제 설명, 예제가 불친절한데... 오목 다각형도 존재할 수 있다.
어쨌든 다각형이 몇각형인지 구하려면 꼭지점의 개수를 구해야 한다.
이건 에디토리얼을 참고했는데 상하좌우 2칸씩 개수를 세서 검은색 블록 (
#)이 1개 또는 3개이면 꼭지점이다.예시를 보면 좀 이해가 가긴 하는데
이건 4각형이고
이건 8각형이 된다
Source Code
All reactions