문제 링크입니다: https://www.acmicpc.net/problem/9298
9298번: Ant Entrapment
For each case output the line “Case x:” where x is the case number, on a single line, followed by the string “Area” and the area of the fence as a floating-point value and then a comma, followed by a space and then “Perimeter” and the perimeter
www.acmicpc.net
간단한 수학 문제였습니다.
This file contains 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> | |
#include <algorithm> | |
using namespace std; | |
const double MAX = 1001; | |
const double MIN = -1001; | |
int main(void) | |
{ | |
int T; | |
cin >> T; | |
for (int t = 1; t <= T; t++) | |
{ | |
int N; | |
cin >> N; | |
double minX = MAX, maxX = MIN; | |
double minY = MAX, maxY = MIN; | |
for (int n = 0; n < N; n++) | |
{ | |
double X, Y; | |
cin >> X >> Y; | |
minX = min(minX, X); | |
maxX = max(maxX, X); | |
minY = min(minY, Y); | |
maxY = max(maxY, Y); | |
} | |
printf("Case %d: ", t); | |
double area = abs((maxX - minX) * (maxY - minY)); | |
double perimeter = abs((maxX - minX) + (maxY - minY)) * 2; | |
printf("Area %.9lf, Perimeter %.9lf\n", area, perimeter); | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 9310번 Arithmetic and Geometric Sums (0) | 2021.07.05 |
---|---|
백준 9299번 Math Tutoring (0) | 2021.07.04 |
백준 9297번 Reducing Improper Fractions (0) | 2021.07.04 |
백준 9295번 주사위 (0) | 2021.07.04 |
백준 9288번 More Dice (0) | 2021.07.04 |