Deep Learning study
백준 17135문제 본문
반응형
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = a; i<b; i++)
#define FOR_(i,a,b) for(int i = a; i>=b; i--)
#define x first
#define y second
int board[16][16],pos[3],tmp[16][16],N,M,D,ANS;
int dist(int a, int b, int c, int d){
return abs(a-c) + abs(b-d);
}
void update(){
FOR_(i,N-1,1) FOR(j,0,M) board[i][j] = board[i-1][j];
FOR(j,0,M) board[0][j] = 0;
}
int attack(){
int min[3] = {99,99,99};
vector<pair<int,int>> co(3);
FOR(i,0,3) co[i].x = 99,co[i].y = 99;
FOR(k,0,3)
FOR(i,0,N)
FOR(j,0,M){
int distance = dist(N, pos[k],i,j);
if(board[i][j] && distance <= D){
if(min[k] == distance && co[k].y > j){
co[k].x = i, co[k].y = j;
}
else if(min[k] > distance){
min[k] = distance, co[k].x = i, co[k].y = j;
}
}
}
int ret = 0;
FOR(i,0,3)
if(co[i].x != 99){
int& enemy = board[co[i].x][co[i].y];
if(enemy) ret++, enemy = 0;
}
return ret;
}
void solve(){
int kill = 0;
FOR(i,0,N){
kill += attack();
update();
}
memcpy(board,tmp,sizeof(tmp));
ANS = max(ANS,kill);
}
void locate(int cnt){
FOR(i,0,M) FOR(j,i+1,M) FOR(k,j+1,M){
pos[0] = i, pos[1] = j, pos[2] = k;
solve();
}
}
int main(){
ios_base::sync_with_stdio(false);
cin >> N >> M >> D;
FOR(i,0,N) FOR(j,0,M) cin >> board[i][j];
memcpy(tmp,board,sizeof(tmp));
locate(0);
cout << ANS << '\n';
return 0;
}
백준 캐슬 디펜스 문제풀이 입니다.
반응형
'백준 문제 코드' 카테고리의 다른 글
백준 14499문제 (0) | 2019.12.12 |
---|---|
백준 14501문제 (0) | 2019.12.10 |
백준 3945문제 (0) | 2019.12.08 |
백준 17406문제 (0) | 2019.12.07 |
백준 17471문제 (0) | 2019.12.07 |
Comments