본문 바로가기
반응형

Algorithm17

[알고리즘] 원자 소멸 시뮬레이션 포인트 1. 전형적인 구현 문제이다. 원자가 없을 때 까지 무한 반복 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. python data = [[0 for _ in range(4001)] for _ in range(4001)] for test in range(1, int(input()) + 1): # 상 하 좌 우 dx = [1, -1, 0, 0] dy = [0, 0, -1, 1] atoms = [] n = int(input()) delete_list = set() total_energy = 0 pop_list = [] # 음수 없애기 for _ in range(n): y, x, move, energy = map(int, input().split()) x = (x + 1000) * 2 y = .. 2021. 3. 8.
[알고리즘 ] Concatenation of Consecutive Binary Numbers 포인트 1. 파이썬은 진법 변환이 엄청 편하며 long long 구별 필요 없이 int 를 사용하면 된다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++/cpp class Solution { public: int concatenatedBinary(int n) { long res = 0, mod = 1e9+7, len_of_curr = 0; for (int i = 1; i 2021. 1. 28.
[알고리즘] 완주하지 못한 선수 포인트 1.잘 구현을 할 수 있는가? 2. 해시를 이용하여 다시 구현을 해보았다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include #include #include using namespace std; string solution(vector participant, vector completion) { sort(participant.begin(), participant.end()); sort(completion.begin(), completion.end()); int num = 0; for(int i=0; i < participant.size(); i++){ if( participant[i] != completion[i]) return participant[i]; .. 2021. 1. 26.
[알고리즘] Contains Duplicate 포인트 1. 중복이 있는지 확인을 하는 코드이다. 2. set을 활용하여 중복이 제거된 크기 기존 크기를 비교하여 중복을 체크한다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. c++ ##include #include using namespace std; class Solution { public: bool containsDuplicate(vector &nums) { unordered_set set; for (auto ele : nums) { if (set.empty()) { set.insert(ele); continue; } auto it = set.find(ele); if (it == set.end()) { set.insert(ele); } else { return true; } } re.. 2021. 1. 21.
반응형