본문 바로가기

USACO/Bronze

백준 12000 Circular Barn (USACO February 2016 Bronze 2번)

문제 링크: https://www.acmicpc.net/problem/12000

 

12000번: Circular Barn (Bronze)

Being a fan of contemporary architecture, Farmer John has built a new barn in the shape of a perfect circle. Inside, the barn consists of a ring of \(n\) rooms, numbered clockwise from \(1 \ldots n\) around the perimeter of the barn (\(3 \leq n \leq 1,000\

www.acmicpc.net

각 방에 exterior door를 열어놨을때의 총거리합들을 구하고, 그중에 최소값을 구함.

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
#include <bits/stdc++.h>
using namespace std;
 
int n, room[1001];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> n;
    for(int i = 1; i <= n; i++cin >> room[i];
 
    int ans = 1e9;
    for(int i = 1; i <= n; i++) {
        int total = 0;
        for(int j = 1; j <= n; j++) {
            if(j >= i) total += (j - i) * room[j];
            else total += (j + n - i) * room[j];
        }
        ans = min(ans, total);
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter