Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

다르(이상엽) - 3주차 #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions boj/darr/1245.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <queue>
#include <math.h>
#include<utility>

using namespace std;

int n,m;
int dx[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int dy[8] = {-1, 1, 0, 0, -1, 1, 1, -1};
int mountain[101][71];
bool check[101][71];

bool checkIsMountainBud(int x, int y) {
bool flag = true;

for(int i=0; i<8; i++) {
int positionX = x + dx[i];
int positionY = y + dy[i];
if(min(positionX, positionY) < 0 || positionX >= n || positionY >= m) continue;
if(mountain[positionX][positionY] > mountain[x][y]) flag = false;
if(check[positionX][positionY]) continue;
if(mountain[positionX][positionY] == mountain[x][y]) {
check[positionX][positionY] = true;
flag = checkIsMountainBud(positionX, positionY) ? flag : false;
}
}

return flag;
}

int main() {
cin>>n>>m;

int answer = 0;

for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
cin>>mountain[i][j];
}
}

for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(mountain[i][j] == 0) continue;
if(check[i][j] == true) continue;
check[i][j] = true;
if(checkIsMountainBud(i, j)) {
answer++;
}
}
}

cout<<answer<<endl;
return 0;
}
51 changes: 51 additions & 0 deletions boj/darr/20167.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int n, k;
int answer = 0;
int energy[21];

void dfs(int process, vector<int> vec) {
if(process == n) {
int total = 0;
int sum = 0;

for(int i=0; i<vec.size(); i++) {
if(vec[i] == -1) {
total += max(0, sum - k);
sum = 0;
} else {
sum += vec[i];
if(sum >= k) {
total += sum - k;
sum = 0;
}
}
}
total += max(0, sum - k);
answer = max(answer, total);

return;
}
vector<int> vec2(vec);
vec.push_back(-1);
vec2.push_back(energy[process]);
dfs(process + 1, vec);
dfs(process + 1, vec2);
}

int main() {
cin>>n>>k;

for(int i=0; i<n; i++) {
cin>>energy[i];
}

vector<int> vec;
dfs(0, vec);

cout<<answer<<endl;
}
52 changes: 52 additions & 0 deletions boj/darr/4889.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <stack>

using namespace std;

int main() {
int number = 1;

while(1) {
int moveCount = 0;
string s;
cin>>s;
if(s[0] == '-') break;

stack<int> stack;
for(int i=0; i<s.size(); i++) {
if(stack.empty()) {
if(s[i] == '}') moveCount++;
stack.push(0);
continue;
}

if(stack.top() == 0 && s[i] == '}') {
stack.pop();
continue;
}

if(stack.top() == 1 && s[i] == '}') {
moveCount++;
stack.pop();
continue;
}

stack.push(s[i] == '{' ? 0 : 1);
}

while(!stack.empty()) {
int top1 = stack.top();
stack.pop();
int top2 = stack.top();
stack.pop();

if(top1 == 0) moveCount++;
if(top2 == 1) moveCount++;
}

cout<<number<<". "<<moveCount<<endl;
number++;
}

return 0;
}
52 changes: 52 additions & 0 deletions boj/darr/6236.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <algorithm>

using namespace std;

int n, m;

bool isValid(int amount[], int n, int m, int midAmount) {
int count = 1; // 첫 번째 인출
int currentAmount = midAmount;

for (int i = 0; i < n; i++) {
if (currentAmount >= amount[i]) {
currentAmount -= amount[i];
} else {
count++;
currentAmount = midAmount - amount[i];
if (currentAmount < 0) return false; // 인출 금액이 하루 지출보다 작다면 불가능
}
}
return count <= m;
}

int main() {
cin >> n >> m;
int amount[n];
int maxAmount = 0;
int sumAmount = 0;

for (int i = 0; i < n; i++) {
cin >> amount[i];
maxAmount = max(amount[i], maxAmount);
sumAmount += amount[i];
}

int minAmount = maxAmount;
int answer = sumAmount;

while (minAmount <= sumAmount) {
int mid = (minAmount + sumAmount) / 2;

if (isValid(amount, n, m, mid)) {
answer = mid;
sumAmount = mid - 1;
} else {
minAmount = mid + 1;
}
}

cout << answer << endl;
return 0;
}