Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Set
- 완전탐색
- 레벨2
- 삼성SW테스트
- BFS
- 백트래킹
- 프로그래머스
- priority_queue
- 이런게4문제
- 2018
- 코딩스킬
- Sort
- 백준
- 모의SW역량테스트
- 레벨3
- swea
- Map
- 삼성
- 문자열
- dfs
- 삼성SW역량테스트
- C++
- 코딩테스트
- 브루트포스
- 시뮬레이션
- STL
- find
- dp
- KAKAO
- substr
Archives
- Today
- Total
-
[삼성SW테스트] 백준 14889번 - 스타트와 링크 (정답률 50%) 본문
https://www.acmicpc.net/problem/14889
14889번: 스타트와 링크
예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다.
www.acmicpc.net
삼성 SW테스트 기출 문제다.
브루트포스 문제로 단순 순열 문제로 바꿔 풀 수 있다.
최적화 안하고 그냥 풀어도 10분도 안걸리는 문제.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 987654321
using namespace std;
int N;
int answer = INF;
vector<vector<int> > ability; // 모든 사람들의 능력치 저장.
vector<int> flag;
vector<int> teamA, teamB;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
cin >> ability[i][j];
}
}
for (int i = 0; i < N / 2; i++){
flag.push_back(0);
flag.push_back(1);
}
sort(flag.begin(), flag.end());
int sum_A = 0, sum_B = 0;
do{
for (int i = 0; i < N; i++){
if (flag[i] == 0){
teamA.push_back(i);
}
else
teamB.push_back(i);
}
for (int i = 0; i < teamA.size(); i++){
int left = teamA[i];
for (int j = 0; j < teamA.size(); j++){
if (i == j)continue;
int right = teamA[j];
sum_A += ability[left][right];
}
}
for (int i = 0; i < teamB.size(); i++){
int left = teamB[i];
for (int j = 0; j < teamB.size(); j++){
if (i == j) continue;
int right = teamB[j];
sum_B += ability[left][right];
}
}
answer = min(answer, abs(sum_A - sum_B));
sum_A = 0, sum_B = 0;
} while (next_permutation(flag.begin(), flag.end()));
cout << answer << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'1-1. 삼성 SW 테스트' 카테고리의 다른 글
[삼성SW테스트] 백준 14503번 - 로봇 청소기 (정답률 50%) (0) | 2020.01.12 |
---|---|
[삼성SW테스트] 백준 14888번 - 연산자 끼워넣기 (정답률 47%) (0) | 2020.01.11 |
[삼성SW테스트] 백준 14891번 - 톱니바퀴 (정답률 50%) (0) | 2020.01.10 |
[삼성SW테스트] 백준 15683번 - 감시 (정답률 39%) (0) | 2020.01.09 |
[삼성SW테스트] 백준 15684번 - 사다리 조작 (0) | 2020.01.06 |
Comments