USACO/Bronze
백준 18270 Livestock Lineup (USACO December 2019 Bronze 3번)
ssam..
2020. 3. 20. 23:12
문제 링크: https://www.acmicpc.net/problem/18270
18270번: Livestock Lineup
Every day, Farmer John milks his 8 dairy cows, named Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, and Sue. The cows are rather picky, unfortunately, and require that Farmer John milks them in an order that respects $N$ constraints ($1 \leq N \
www.acmicpc.net
소들을 알파벳 순서데로 정렬하고나서 모든 순열을 next_permutation을 이용하여 돌려보다가, 모든 조건을 충족시키는 permutation이 나오면 답을 출력하면 됨.
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
|
#include <bits/stdc++.h>
using namespace std;
int n;
string cow[9] = {"Bessie", "Buttercup", "Belinda", "Beatrice", "Bella", "Blue", "Betsy", "Sue"};
string xy[8][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
string a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
xy[i][0] = a;
xy[i][1] = f;
}
sort(cow, cow + 8);
do {
int cnt = 0;
for(int i = 0; i < n; i++) {
for(int k = 0; k < 8; k++) {
if(cow[k] == xy[i][0] && cow[k + 1] == xy[i][1]) cnt++;
if(cow[k] == xy[i][1] && cow[k + 1] == xy[i][0]) cnt++;
}
}
if(cnt == n) {
for(int i = 0; i < 8; i++)
cout << cow[i] << '\n';
return 0;
}
} while(next_permutation(cow, cow + 8));
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|