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
- C/C++ 구현
- 백준
- 백준 1158
- 자료구조
- dfs
- qorwns
- ㅣ풀이
- 게리멘더링2
- 1764
- heap
- 조세퍼스 순열
- 백준 1406
- 백준 17471
- 풀이
- c#
- 5397
- 스택의 특징
- 백준 5397
- 백준 17779
- 구현
- 백준 2447
- 시간 복잡도
- Stack 이란
- 백준 17822
- AVL 시간 복잡도
- 버킷 정렬
- 원판 돌리기
- 해시 구현
- 별 찍기 10
- 해시구현
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 16956] 늑대와 양 본문
분류
구현
요구사항
양에게 늑대가 접근하지 못하도록 벽 쌓기
풀이
모든 빈칸에 벽을 쌓아보고 늑대가 양에게 접근할 수 있는지 판단한다
위 경우, 양 바로 옆에 늑대가 있는 경우에만 접근이 가능하다
#include <string>
#include <vector>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
using namespace std;
struct go{
int x;
int y;
};
int n,m;
char map[501][501];
vector<go> v;
int dr[4] = {-1,0,1,0};
int dc[4] = {0,-1,0,1};
int main(){
scanf("%d%d",&n,&m);
for(int i=0 ; i < n ; i++){
for(int j=0 ; j <m ; j++){
scanf(" %c",&map[i][j]);
if(map[i][j]=='W'){
v.push_back({i,j});
}
}
}
for(int i=0 ; i < n ; i++){
for(int j=0 ; j <m ; j++){
if(map[i][j]=='.'){
map[i][j]='D';
}
}
}
int flag=0;
for(int i=0 ; i <v.size(); i++){
int r = v[i].x;
int c = v[i].y;
for(int j=0 ; j <4; j++){
int nr = r+dr[j];
int nc = c+dc[j];
if(nr<0 || nc<0 || nr>=n || nc>=m) continue;
if(map[nr][nc]=='S')
{
// cout<<"nr"<<nr<<" "<<nc<<endl;
flag=1;
break;
}
}
if(flag==1) break;
}
if(flag==0){
cout<<"1"<<endl;
for(int i=0 ; i < n ; i++){
for(int j=0 ; j <m ; j++){
cout<<map[i][j];
}
cout<<endl;
}
}
else{
cout<<"0"<<endl;
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 3568] iSharp (0) | 2020.05.18 |
---|---|
[백준 14888] 연산자 끼워넣기 (0) | 2020.05.18 |
[백준 14501] 퇴사 (0) | 2020.05.16 |
[백준 17472] 다리 만들기2 (0) | 2020.05.14 |
[백준 17281] 야구 (0) | 2020.05.03 |
Comments