Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

코드와이

[BAEKJOON] 1198. 삼각형으로 자르기 본문

acmicpc

[BAEKJOON] 1198. 삼각형으로 자르기

코드와이 2021. 2. 13. 21:47

 

문제링크

www.acmicpc.net/problem/1198

 

1198번: 삼각형으로 자르기

볼록 다각형이 있고, 3개의 연속된 점을 선택해서 삼각형을 만든다. 그 다음이 만든 삼각형을 다각형에서 제외한다. 원래 다각형이 N개의 점이 있었다면, 이제 N-1개의 점으로 구성된 볼록 다각형

www.acmicpc.net

 

package acmicpc.Silver3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class 삼각형으로_자르기 {

	static int[] arr_x;
	static int[] arr_y;
	static int[] numbers;
	static int[] input;
	static int n;
	static double ans;
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		n = Integer.parseInt(br.readLine());
		
		arr_x = new int[n];
		arr_y = new int[n];
		
		for(int i = 0 ; i < n ; i++) {
			st = new StringTokenizer(br.readLine(), " ");
			arr_x[i] = Integer.parseInt(st.nextToken());
			arr_y[i] = Integer.parseInt(st.nextToken());
		}
		ans = 0;
		numbers = new int[3];
		input = new int[n];
		for(int i = 0 ; i < n ; i++) {
			input[i] = i;
		}
		func(0,0);
		
		System.out.println(ans);
	}
	
	public static Double S(int x1, int y1, int x2, int y2, int x3, int y3) {
		
		double d = x1 * y2 + x2 * y3 + x3 * y1 - x2 * y1 - x3 * y2 - x1 * y3;
		return Math.abs(d / 2);
	}
	
	public static void func(int cnt, int idx) {
		
		if( cnt == 3 ) {
			ans = Math.max(ans, S(arr_x[numbers[0]], arr_y[numbers[0]], arr_x[numbers[1]], arr_y[numbers[1]], arr_x[numbers[2]], arr_y[numbers[2]]));
			return;
		}
		
		for(int i = idx ; i < n ; i++) {
			numbers[cnt] = input[i];
			func(cnt + 1, i + 1);
		}
	}
}

'acmicpc' 카테고리의 다른 글

[BAEKJOON] 1262. 알파벳 다이아몬드  (0) 2021.02.15
[BAEKJOON] 1269. 대칭 차집합  (0) 2021.02.15
[BAEKJOON] 1166. 선물  (0) 2021.02.13
[BAEKJOON] 1124. 언더프라임  (0) 2021.02.13
[BAEKJOON] 17478.재귀함수가 뭔가요?  (0) 2021.02.10