문제 링크입니다: www.acmicpc.net/problem/2863
2863번: 이게 분수?
첫째 줄에 표를 몇 번 돌려야 표의 값이 최대가 되는지 출력한다. 만약, 그러한 값이 여러개라면 가장 작은 값을 출력한다.
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MAX = 2; | |
const int MAX_ROTATION = 4; | |
void rotate(double (*arr)[MAX]) | |
{ | |
double temp[MAX][MAX]; | |
for (int i = 0; i < MAX; i++) | |
{ | |
for (int j = 0; j < MAX; j++) | |
{ | |
temp[j][MAX - (i + 1)] = arr[i][j]; | |
} | |
} | |
for (int i = 0; i < MAX; i++) | |
{ | |
for (int j = 0; j < MAX; j++) | |
{ | |
arr[i][j] = temp[i][j]; | |
} | |
} | |
} | |
double getScore(double arr[][MAX]) | |
{ | |
return arr[0][0] / arr[1][0] + arr[0][1] / arr[1][1]; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
double arr[MAX][MAX]; | |
for (int i = 0; i < MAX; i++) | |
{ | |
for (int j = 0; j < MAX; j++) | |
{ | |
cin >> arr[i][j]; | |
} | |
} | |
double maxScore = 0.0; | |
int result = 0; | |
for (int i = 0; i < MAX_ROTATION; i++) | |
{ | |
if (getScore(arr) > maxScore) | |
{ | |
maxScore = getScore(arr); | |
result = i; | |
} | |
rotate(arr); | |
} | |
cout << result << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2903번 중앙 이동 알고리즘 (0) | 2021.04.25 |
---|---|
백준 2884번 알람 시계 (0) | 2021.04.25 |
백준 2783번 삼각 김밥 (0) | 2021.04.25 |
백준 21355번 Personnummer (0) | 2021.04.25 |
백준 21354번 Äpplen och päron (0) | 2021.04.25 |