fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 6127 (C++) Super Paintball
최초 업로드: 2025-09-23 16:22:49
최근 수정 시간: 2025-09-23 16:25:13
게시자: rlatjwls3333
카테고리: 백준
조회수: 11
# [Silver IV] Super Paintball [문제 링크](https://www.acmicpc.net/problem/6127) ## 문제 설명 <p>The cows have purchased a Super Paintball Deluxe game set from Tycow, the cow-toy manufacturer. Bessie, knowing you can help, has partitioned the pasture into a set of N x N unit squares (1 <= N <= 100) and compiled a list of the K (1 <= K <= 100,000) locations (1 <= R_i <= N; 1 <= C_i <= N) of every one of her opponents in the Paintball game.</p> <p>This paintball game features a paintball gun that can shoot paintballs in any of eight directions: north, south, east, west, and the diagonals that split those directions exactly (northeast, southeast, northwest, southwest).</p> <p>Bessie wants you to tell her the total number of squares she can occupy and still be able to shoot all of her opponents (she can even shoot them if she shares the same square as they occupy!).</p> ## 입력 <ul> <li>Line 1: Two space-separated integers: N and K</li> <li>Lines 2..K+1: Line i+1 describes cow i's location with two space-separated integers: R_i and C_i</li> </ul> ## 출력 <ul> <li>Line 1: A single integer that tells how many different locations Bessie may occupy if she is to be able to shoot any cow according to the shooting rules.</li> </ul> ## 풀이 직접 모든 점에 대해 8방향으로 움직여보며 모든 cow의 위치가 커버되는지 확인해보면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; int n, k; int board[100][100]; bool chk(int r, int c) { int cnt = board[r][c]; for(int i=1;i<200;i++) { if(c+i<n) cnt += board[r][c+i]; if(c-i>=0) cnt += board[r][c-i]; if(r+i<n) cnt += board[r+i][c]; if(r+i<n && c+i<n) cnt += board[r+i][c+i]; if(r+i<n && c-i>=0) cnt += board[r+i][c-i]; if(r-i>=0) cnt += board[r-i][c]; if(r-i>=0 && c+i<n) cnt += board[r-i][c+i]; if(r-i>=0 && c-i>=0) cnt += board[r-i][c-i]; } return cnt == k; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i=0;i<k;i++) { int r, c; cin >> r >> c; board[r-1][c-1]++; } int cnt=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(chk(i, j)) cnt++; } } cout << cnt; } ```