티스토리 뷰
14921번: 용액 합성하기
홍익대 화학연구소는 다양한 용액을 보유하고 있다. 각 용액은 -100,000,000부터 100,000,000사이의 특성 값을 갖는데, 같은 양의 두 용액을 혼합하면, 그 특성값은 두 용액의 특성값의 합이 된다. 당
www.acmicpc.net
백준 소스코드 [C++] 14921 용액 합성하기
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int n;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n; v.resize(n);
for (int i = 0;i < n;i++) cin >> v[i];
int L = 0, R = n-1, here=abs(v[L]+v[R]),there;
int l = 0, r = n-1;
while (L<R) {
there = v[L] + v[R];
if (here > abs(there)) {
here = abs(there);
l = L, r = R;
}
if (there < 0) L++;
else R--;
}
cout << v[l] + v[r];
return 0;
}
'백준' 카테고리의 다른 글
백준 소스코드 [C++] 17404 RGB거리 2 (0) | 2021.03.02 |
---|---|
백준 소스코드 [C++] 2473 세 용액 (0) | 2021.03.02 |
백준 소스코드 [C++] 2470 두 용액 (0) | 2021.03.02 |
백준 소스코드 [C++] 2467 용액 (0) | 2021.03.02 |
백준 소스코드 [C++] 12920 평범한 배낭 2 (0) | 2021.03.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- 최대 매칭
- 최단경로 문제
- 벨만포드 시간복잡도
- rxswift
- 네트워크 플로우
- 최단경로 알고리즘
- 에드몬드 카프 알고리즘
- 코딩대회
- 네트워크 유량
- Testable
- WWDC19
- WWDC16
- CPU와 Memory
- test coverage
- WWDC17
- HIG
- MeTal
- IOS
- 다익스트라 시간복잡도
- 포드 풀커슨 알고리즘
- State Restoration
- WWDC21
- observeOn
- 컴퓨터 추상화
- mach-o
- 최단경로문제
- 부스트캠프 6기
- 강한 순환 참조
- CompositionalLayout
- 벨만포드 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함