Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 |
| 31 |
Tags
- 백준
- 이분탐색
- Java
- 운동기록
- 프로그래머스
- db
- binary search
- 러닝일지
- 문자열
- priorityqueue
- 문제해결
- 시뮬레이션
- 문제풀이
- greedy
- oracle
- BOJ
- MySQL
- 건강
- 자바
- 투포인터
- BFS
- SQL
- dfs
- SWEA
- 코테
- 알고리즘
- DP
- 코딩테스트
- COS PRO
- math
Archives
- Today
- Total
슈콩
[SWEA] 사랑의 카운슬러 본문


[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWlQUD2qtysDFAVS
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.io.*;
import java.util.*;
public class Solution {
static int n;
static long result;
static long[][] info;
static boolean[] visit;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int tc=1;tc<=T;tc++) {
n = Integer.parseInt(br.readLine());
info = new long[n][2];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
info[i][0] = Long.parseLong(st.nextToken());
info[i][1] = Long.parseLong(st.nextToken());
}
visit = new boolean[n];
result = Long.MAX_VALUE;
select(0,0);
System.out.println("#"+tc+" "+result);
}
}
private static void select(int idx,int cnt) {
if(cnt==n/2) {
long nx = 0;
long ny = 0;
for(int i=0;i<n;i++) {
if(visit[i]) {
nx += info[i][0];
ny += info[i][1];
}
else {
nx -= info[i][0];
ny -= info[i][1];
}
}
long sum = nx*nx + ny*ny;
result = Math.min(result, sum);
return;
}
for(int i=idx;i<n;i++) {
visit[i] = true;
select(i+1,cnt+1);
visit[i] = false;
}
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 화섭이의 정수 나열 (0) | 2025.11.15 |
|---|---|
| [SWEA] 공평한 분배 2 (0) | 2025.11.15 |
| [SWEA] 신뢰 (0) | 2025.11.15 |
| [SWEA] 알파벳 공부 (0) | 2025.11.14 |
| [SWEA] 힙 (0) | 2025.11.14 |