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
- 5397
- C/C++ 구현
- 원판 돌리기
- 해시 구현
- 구현
- 백준
- Stack 이란
- 조세퍼스 순열
- 백준 17822
- 스택의 특징
- ㅣ풀이
- 풀이
- c#
- 백준 17471
- 별 찍기 10
- 자료구조
- 해시구현
- 백준 1158
- 백준 1406
- 1764
- dfs
- qorwns
- 게리멘더링2
- 버킷 정렬
- heap
- AVL 시간 복잡도
- 백준 5397
- 백준 2447
- 백준 17779
- 시간 복잡도
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 16235] 나무 재테크 본문
https://www.acmicpc.net/problem/16235
16235번: 나무 재테크
부동산 투자로 억대의 돈을 번 상도는 최근 N×N 크기의 땅을 구매했다. 상도는 손쉬운 땅 관리를 위해 땅을 1×1 크기의 칸으로 나누어 놓았다. 각각의 칸은 (r, c)로 나타내며, r은 가장 위에서부터 떨어진 칸의 개수, c는 가장 왼쪽으로부터 떨어진 칸의 개수이다. r과 c는 1부터 시작한다. 상도는 전자통신공학과 출신답게 땅의 양분을 조사하는 로봇 S2D2를 만들었다. S2D2는 1×1 크기의 칸에 들어있는 양분을 조사해 상도에게 전송하고, 모든
www.acmicpc.net
요구사항
k 시간 지난 후, 나무 개수 구하기
풀이
1. 봄, 여름, 가을, 겨울의 조건대로 구현한다
2. 봄에 먹이를 줄때, 여름의 경우를 같이 처리해준다
3. 5의 배수일때 번식을 하므로, 이 경우도 고려해서 처리한다.
#include<iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <string.h>
using namespace std;
//priority_queue<int,vector<int>,greater<>> map[11][11];
vector<int> map[11][11];
int visit[11][11];
int eat[11][11];
int now[11][11];
int dr[8] = { -1,-1,-1,0,1,1,1,0 };
int dc[8] = { -1,0,1,1,1,0,-1,-1 };
int n, m, k;
int ans = 0;
void show() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << map[i][j].size() << " ";
}
cout << endl;
}
cout << endl;
}
bool com(int a, int b) {
if (a > b) return true;
return false;
}
void solve() {
while (k--) {
// show();
memset(visit, 0, sizeof(visit));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j].size() > 0) {
vector<int> nq;
sort(map[i][j].begin(), map[i][j].end(), com);
int s = map[i][j].size();
int tempsum = 0;
//크기만큼
for (int k = 0; k < s; k++) {
int nowtop = map[i][j].back();
if (now[i][j] - nowtop >= 0) {
map[i][j].pop_back();
now[i][j] = now[i][j] - nowtop;
nq.push_back(nowtop + 1);
if (nowtop != 0 && (nowtop + 1) % 5 == 0) {
visit[i][j]++;
}
}
else {
map[i][j].pop_back();
int temp = nowtop / 2;
tempsum += temp;
}
}
map[i][j] = nq;
now[i][j] += tempsum;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
now[i][j] += eat[i][j];
if (visit[i][j] > 0) {
for (int k = 0; k < visit[i][j]; k++) {
for (int a = 0; a < 8; a++) {
int nr = i + dr[a];
int nc = j + dc[a];
if (nr < 0 || nc < 0 || nr >= n || nc >= n)
continue;
map[nr][nc].push_back(1);
}
}
}
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans += map[i][j].size();
}
// cout<<endl;
}
}
int main()
{
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> eat[i][j];
now[i][j] = 5;
}
}
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
map[x - 1][y - 1].push_back(z);
}
solve();
// cout<<"B"<<endl;
cout << ans << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 14890] 경사로 (0) | 2020.02.08 |
---|---|
[백준 14889] 스타트와 링크 (0) | 2020.02.08 |
[백준 17144] 미세먼지 안녕 (0) | 2020.02.04 |
[백준 17140] 이차원 배열과 연산 (0) | 2020.02.02 |
[백준 17142] 연구소 3 (0) | 2020.02.02 |
Comments