Skip to content

Commit 28e5457

Browse files
committed
[Silver II] Title: 참외밭, Time: 104 ms, Memory: 14276 KB -BaekjoonHub
1 parent 37b411f commit 28e5457

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# [Silver II] 참외밭 - 2477
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2477)
4+
5+
### 성능 요약
6+
7+
메모리: 14276 KB, 시간: 104 ms
8+
9+
### 분류
10+
11+
기하학, 구현, 수학
12+
13+
### 제출 일자
14+
15+
2025년 1월 8일 10:40:54
16+
17+
### 문제 설명
18+
19+
<p>시골에 있는 태양이의 삼촌 댁에는 커다란 참외밭이 있다. 문득 태양이는 이 밭에서 자라는 참외가 도대체 몇 개나 되는지 궁금해졌다. 어떻게 알아낼 수 있는지 골똘히 생각하다가 드디어 좋은 아이디어가 떠올랐다. 유레카! 1m<sup>2</sup>의 넓이에 자라는 참외 개수를 헤아린 다음, 참외밭의 넓이를 구하면 비례식을 이용하여 참외의 총개수를 구할 수 있다.</p>
20+
21+
<p>1m<sup>2</sup>의 넓이에 자라는 참외의 개수는 헤아렸고, 이제 참외밭의 넓이만 구하면 된다. 참외밭은 ㄱ-자 모양이거나 ㄱ-자를 90도, 180도, 270도 회전한 모양(┏, ┗, ┛ 모양)의 육각형이다. 다행히도 밭의 경계(육각형의 변)는 모두 동서 방향이거나 남북 방향이었다. 밭의 한 모퉁이에서 출발하여 밭의 둘레를 돌면서 밭경계 길이를 모두 측정하였다.</p>
22+
23+
<p style="text-align: center;"><img alt="" src="https://www.acmicpc.net/upload/images/qqq.png" style="width: 193px; height: 93px; "></p>
24+
25+
<p>예를 들어 참외밭이 위 그림과 같은 모양이라고 하자. 그림에서 오른쪽은 동쪽, 왼쪽은 서쪽, 아래쪽은 남쪽, 위쪽은 북쪽이다. 이 그림의 왼쪽위 꼭짓점에서 출발하여, 반시계방향으로 남쪽으로 30m, 동쪽으로 60m, 남쪽으로 20m, 동쪽으로 100m, 북쪽으로 50m, 서쪽으로 160m 이동하면 다시 출발점으로 되돌아가게 된다.</p>
26+
27+
<p>위 그림의 참외밭 면적은 6800m<sup>2</sup>이다. 만약 1m<sup>2</sup>의 넓이에 자라는 참외의 개수가 7이라면, 이 밭에서 자라는 참외의 개수는 47600으로 계산된다.</p>
28+
29+
<p>1m<sup>2</sup>의 넓이에 자라는 참외의 개수와, 참외밭을 이루는 육각형의 임의의 한 꼭짓점에서 출발하여 반시계방향으로 둘레를 돌면서 지나는 변의 방향과 길이가 순서대로 주어진다. 이 참외밭에서 자라는 참외의 수를 구하는 프로그램을 작성하시오.</p>
30+
31+
### 입력
32+
33+
<p>첫 번째 줄에 1m<sup>2</sup>의 넓이에 자라는 참외의 개수를 나타내는 양의 정수 K (1 ≤ K ≤ 20)가 주어진다. 참외밭을 나타내는 육각형의 임의의 한 꼭짓점에서 출발하여 반시계방향으로 둘레를 돌면서 지나는 변의 방향과 길이 (1 이상 500 이하의 정수) 가 둘째 줄부터 일곱 번째 줄까지 한 줄에 하나씩 순서대로 주어진다. 변의 방향에서 동쪽은 1, 서쪽은 2, 남쪽은 3, 북쪽은 4로 나타낸다.</p>
34+
35+
### 출력
36+
37+
<p>첫째 줄에 입력으로 주어진 밭에서 자라는 참외의 수를 출력한다.</p>
38+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
static int maxHeight, maxWidth, widthIndex, heightIndex, length[];
6+
public static void main(String[] args) throws IOException {
7+
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
10+
int K = Integer.parseInt(br.readLine());
11+
12+
StringTokenizer st;
13+
14+
maxHeight = Integer.MIN_VALUE;
15+
maxWidth = Integer.MIN_VALUE;
16+
widthIndex = 0;
17+
heightIndex = 0;
18+
length= new int[6];
19+
20+
for(int i = 0; i<6; i++) {
21+
st= new StringTokenizer(br.readLine());
22+
23+
int dir = Integer.parseInt(st.nextToken());
24+
25+
length[i] = Integer.parseInt(st.nextToken());
26+
27+
if(dir == 1 || dir ==2) {
28+
if(maxWidth < length[i]) {
29+
maxWidth = length[i];
30+
widthIndex = i;
31+
}
32+
}
33+
34+
else if(dir ==3 || dir ==4) {
35+
if(maxHeight < length[i]) {
36+
maxHeight = length[i];
37+
heightIndex = i;
38+
}
39+
}
40+
}
41+
42+
int tempWidth = lengthCal(heightIndex);
43+
int tempHeight = lengthCal(widthIndex);
44+
45+
int result = ((maxHeight * maxWidth) - (tempHeight * tempWidth)) *K;
46+
47+
System.out.println(result);
48+
}
49+
50+
51+
static int lengthCal(int index ) {
52+
53+
int result = 0;
54+
if (index ==0 ) {
55+
result = Math.abs(length[index+1] - length[5]);
56+
}
57+
else if(index ==5) {
58+
result = Math.abs(length[index-1] - length[0]);
59+
}
60+
61+
else {
62+
result = Math.abs(length[index+1] - length[index-1]);
63+
}
64+
65+
return result;
66+
}
67+
}

0 commit comments

Comments
 (0)