본문 바로가기

Competition/codeforces

Codeforces Round #526 (Div. 2) A. The Fair Nut and Elevator


A. The Fair Nut and Elevator

https://codeforces.com/problemset/problem/1084/A


완전탐색 문제이다.

모든 층을 탐색하면서 최소의 값을 찾는다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
 
int n, minv, tempmin, multi, arr[101];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++)    cin >> arr[i];
    minv = 1e9;
    for (int i = 0; i < n; i++) {
        tempmin = 0;
        for (int j = 0; j < n; j++) {
            multi = 2 * (max(j - i, i - j) + j + i);
            tempmin += arr[j] * multi;
        }
        minv = min(tempmin, minv);
    }
    cout << minv;
    return 0;
}
cs