※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26544번 문제인 Histogram Fencing이다.
문제는 아래 링크를 확인하자
https://www.acmicpc.net/problem/26544
26544번: Histogram Fencing
Your next-door neighbor has asked to borrow some fencing to put around all of his land. Being the kind neighbor that you are, you’ve decided to lend him your fencing. But being the stingy farmer that you are, you’ve also decided to give him exactly eno
www.acmicpc.net
주어지는 히스토그램모양의 땅의 둘레를 구하는 문제이다.
밑변의 길이의 2배로 가로선의 길이의 합을, 인접한 두 막대의 길이의 차로 각 세로선의 길이를 구해 합쳐 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
int T, N;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
ll ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
ll x; cin >> x;
ans += x;
}
ans *= 2;
ll old = 0;
for (int i = 0; i < N; i++) {
ll x; cin >> x;
ans += abs(x - old);
old = x;
}
ans += old;
cout << ans << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 17828 // C++] 문자열 화폐 (0) | 2022.12.23 |
---|---|
[BOJ 26565 // C++] Time Limits (0) | 2022.12.23 |
[BOJ 11580 // C++] Footprint (0) | 2022.12.23 |
[BOJ 26731 // C++] Zagubiona litera (0) | 2022.12.23 |
[BOJ 6903 // C++] Trident (0) | 2022.12.23 |