Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 다익스트라
- 유니온 파인드
- XR Interaction Toolkit
- BFS
- 백트래킹
- Unreal Engine 5
- Team Fortress 2
- VR
- ue5
- 브루트포스
- 구현
- 트리
- 우선순위 큐
- c++
- 정렬
- 문자열
- 수학
- 자료구조
- 재귀
- 투 포인터
- 그래프
- 스택
- 누적 합
- 그리디 알고리즘
- 시뮬레이션
- 백준
- 유니티
- 다이나믹 프로그래밍
- 알고리즘
- DFS
Archives
- Today
- Total
1일1알
백준 1270번 전쟁-땅따먹기 C++ 본문
map 자료구조를 이용해 문제를 해결하였다.
unordered_map을 사용하면 시간이 조금 단축된다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
map<ll, int> mp;
bool isBattle = true;
ll ans = 0;
cin >> t;
int half = t / 2;
for (int j = 0; j < t; j++) {
ll soldier;
cin >> soldier;
mp[soldier]++;
if (mp[soldier] > half) {
ans = soldier;
isBattle = false;
}
}
if (isBattle) cout << "SYJKGW";
else cout << ans;
cout << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 1292번 쉽게 푸는 문제 C++ (0) | 2022.04.21 |
---|---|
백준 1283번 단축키 지정 C++ (0) | 2022.04.20 |
백준 1251번 단어 나누기 C++ (0) | 2022.04.18 |
백준 1244번 스위치 켜고 끄기 C++ (0) | 2022.04.17 |
백준 1235번 학생 번호 C++ (0) | 2022.04.16 |