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

6월 1주차 Hojun #115

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
39 changes: 39 additions & 0 deletions 2023/06_June/week1/이호준/boj_17425_약수의합.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************
Algorithm Study
Baekjoon 17425 약수의 합
2023/06/10 이호준
# 아이디어
1. 누적합
*******************************************************************/
#include <iostream>
#define MAX 1000001

using namespace std;
typedef long long ll;

ll dp[MAX];
int main(void){

ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int t, n;
ll sum = 0;
cin >> t;

for(int i = 1; i <= MAX; ++i){
for(int j = i; j <= MAX; j+=i){
dp[j] += i;
}
}

for(int i = 2; i <= MAX; i++){
dp[i] += dp[i-1];
}

while (t--){
cin >> n;
cout << dp[n] <<"\n";
}

return 0;
}
117 changes: 117 additions & 0 deletions 2023/06_June/week1/이호준/boj_177779_게더멘더링2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*******************************************************************
Algorithm Study
Baekjoon 177779 게더멘더링2
2023/06/11 이호준
# 아이디어
1. 구현
*******************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N, total;
int answer = 2000000000;
int A[25][25];

// 구역 나누고, population 벡터에 각 구역 인구 저장
void DivideArea(const int x, const int y, const int d1, const int d2, vector<vector<int>> &board, vector<int> &population)
{
// 1
int cnt = 0;
for(int i = 1; i < x + d1; i++)
{
if(i >= x) cnt++;
for(int j = 1; j <= y - cnt; j++)
{
population[1] += A[i][j];
}
}

// 2
cnt = 0;
for(int i = 1; i <= x+d2; i++)
{
if(i > x) cnt++;
for(int j = y+1+cnt; j <= N; j++)
{
population[2] += A[i][j];
}
}

// 3
cnt = 0;
for(int i = N; i >= x + d1; i--)
{
if(i < x+d1+d2) cnt++;
for(int j = 1; j < y+d2-d1-cnt; j++)
{
population[3] += A[i][j];
}
}

// 4
cnt = 0;
for(int i = N; i > x+d2; i--)
{
if(i <= x+d1+d2) cnt++;
for(int j = y+d2-d1+cnt; j <= N; j++)
{
population[4] += A[i][j];
}
}
}

void Print(vector<vector<int>> board)
{
cout << endl;
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
cout << board[i][j] << ' ';
} cout << endl;
} cout << endl;
}


int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> N;
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
cin >> A[i][j];
total += A[i][j];
}
}

for(int x = 1; x < N; x++)
{
for(int y = 0; y < N; y++)
{

for(int d1 = 1; d1 < N; d1++)
{
for(int d2 = 1; d2 < N; d2++)
{
if(x+d1 > N || y-d1 <= 0) continue; // 좌측 꼭지점
if(x+d2 > N || y+d2 > N) continue; // 우측 꼭지점
if(x+d1+d2 > N || y+d2-d1 <= 0) continue; // 아래 꼭지점
if(x+d2+d1 > N || y-d1+d2 > N) continue;

vector<vector<int>> board(N+1, vector<int>(N+1, 0));
vector<int> population(6);
DivideArea(x, y, d1, d2, board, population);
population[5] = total - (population[1]+population[2]+population[3]+population[4]);
sort(population.begin(), population.end());
answer = min(answer, population[5] - population[1]);
}
}
}
}

cout << answer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************
Algorithm Study
Baekjoon 21278 호석이 두 마리 치킨
2023/06/10 이호준
# 아이디어
1. BruteForce, 플로이드와샬
*******************************************************************/
#include<iostream>
#include<vector>
#include<algorithm>

#define INF 1000000000

using namespace std;

int n, m;
int dist[101][101];

int calDistance(int x, int y){
int distance = 0;
for (int i = 1; i <= n; i++)
distance += min(dist[x][i], dist[y][i]);
return distance;
}

void floydWarshall(){
for(int i = 1; i <= n; ++i){
for (int j = 1; j <= n; ++j) {
if (i == j) continue;
else if (!dist[i][j])
dist[i][j] = INF;
}
}
for (int k = 1; k <= n; ++k)
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main(void){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int x, y;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> x >> y;
dist[x][y] = dist[y][x] = 1;
}

floydWarshall();

pair<int,int> chicken;
int answer = INF;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++){
int temp = calDistance(i, j);
if (answer > temp) {
chicken = {i, j};
answer = temp;
}
}
cout << chicken.first <<" " << chicken.second <<" "<< answer * 2;
return 0;
}
44 changes: 44 additions & 0 deletions 2023/06_June/week1/이호준/boj_21758_꿀따기.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************
Algorithm Study
Baekjoon 21758 꿀따기
2023/06/11 이호준
# 아이디어
1. 누적합
*******************************************************************/
#include <iostream>

#define MAX 100001

using namespace std;

int arr[MAX], sum[MAX];

int getPrefixSum(int a, int b) {
return sum[b] - sum[a - 1];
}

int main(void){

ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int n;
cin >> n;

for (int i = 1; i <= n; i++){
cin >> arr[i];
sum[i] = sum[i - 1] + arr[i];
}

int res = 0;
for (int i = 2; i < n; i++)
res = max(res, getPrefixSum(2, n) + getPrefixSum(i + 1, n) - arr[i]);

for (int i = n - 1; i > 1; i--)
res = max(res, getPrefixSum(1, n - 1) + getPrefixSum(1, i - 1) - arr[i]);

for(int i = 2; i <= n - 1; i++)
res = max(res, getPrefixSum(2, n - 1) + arr[i]);

cout << res;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************
Algorithm Study
Baekjoon 22871 징검다리건너기(Large)
2023/06/10 이호준
# 아이디어
1. DP
*******************************************************************/
#include <iostream>
#include <algorithm>

#define MAX 5001

using namespace std;

typedef long long ll;

int N = 5001;
int n;
ll arr[MAX], dp[MAX];

ll go(int x) {
if (x == n - 1) return 0;
ll& ret = dp[x];
if (ret != 0) return ret;

ret = 1e10;
for (int i = x + 1; i < n; i++) {
ret = min(ret, max(go(i), (i - x) * (1 + abs(arr[x] - arr[i]))));
}
return ret;
}

int main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

cin >> n;

for (int i = 0; i < n; ++i)
cin >> arr[i];

cout << go(0);

return 0;
}
1 change: 0 additions & 1 deletion 2023/06_June/week1/이호준/hello.txt

This file was deleted.