반응형
    
    
    
  
                              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 | 29 | 30 | 31 | 
                            Tags
                            
                        
                          
                          - 성적평가
- 이분탐색
- OFFSET
- 처우협의
- 13908
- 매개변수탐색
- BOJ
- 오퍼레터
- 물채우기
- incr
- 퇴사통보
- dfs
- 소프티어
- upper_bound
- 처우산정
- Kafka
- 백준
- @P0
- Docker
- softeer
- msSQL
- compose
- 경력
- 6987
- 연결요소
- BFS
- 백트래킹
- boj #19237 #어른 상어
- 기술면접
- 파라메트릭
                            Archives
                            
                        
                          
                          - Today
- Total
기술 블로그
길 찾기 게임 본문
728x90
    
    
  반응형
    
    
    
  https://programmers.co.kr/learn/courses/30/lessons/42892
tempRoot는 필요없다.
| 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #include <bits/stdc++.h> using namespace std; typedef struct node {     int x, y, data;     struct node * left;     struct node * right; }node; node * root, * tempRoot; vector<int> vectorPre, vectorPost; vector< pair<int, vector<int> > > v; void search(node * temp, node * answer) {     if (root == NULL)     {         root = (node*)malloc(sizeof(node));         root->x = temp->x;         root->y = temp->y;         root->data = temp->data;         root->left = root->right = NULL;         tempRoot = root;         return;     }     if (answer->y > temp->y && answer->x > temp->x)     {         if (answer->left == NULL) answer->left = temp;             else search(temp, answer->left);     }     else if (answer->y > temp->y && answer->x < temp->x)     {         if (answer->right == NULL) answer->right = temp;         else search(temp, answer->right);     } } void create(int x, int y, int data) {     node * temp = (node*)malloc(sizeof(node));     temp->x = x;      temp->y = y;     temp->data = data;     temp->left = temp->right = NULL;     search(temp, root); } void preOrder(node * preNode) {     if (preNode != NULL)     {         vectorPre.push_back(preNode->data);         preOrder(preNode->left);         preOrder(preNode->right);     } } void postOrder(node * postNode) {     if (postNode != NULL)     {         postOrder(postNode->left);         postOrder(postNode->right);         vectorPost.push_back(postNode->data);             } } bool cmp(const pair<int, vector<int> > & a, const pair<int, vector<int> > & b) {     return a.second.at(1) > b.second.at(1); } vector<vector<int>> solution(vector<vector<int>> nodeinfo)  {     vector<vector<int>> answer;     for (int i = 0; i < nodeinfo.size(); i++)         v.push_back({ i + 1, nodeinfo.at(i) });     sort(v.begin(), v.end(), cmp);     for (auto i : v)         create(i.second.at(0), i.second.at(1), i.first);     preOrder(root);     postOrder(root);     answer.push_back(vectorPre);     answer.push_back(vectorPost);     return answer; } | cs | 
728x90
    
    
  반응형
    
    
    
  