본문 바로가기

분류 전체보기

(602)
LNK2019 에러가 날 때.. LNK 는 링크 관련 에러이다. 보통 오브젝트 파일을 생성한 후 링킹을 시도하면서 특정 파일을 찾지 못하는 경우 발생한다. 문제를 해결하기 위해 Visual Studio 의 Project 를 마우스 우클릭 > Properties > 창 왼쪽 영역의 Configuration Properties > Linker > General 을 들어간 후 Additional Library Directories 에서 참조하는 파일을 추가하면 된다. 이 방법 말고 또 하나의 방법이 있는데, 바로 코드 상에서 #pragma comment(...)를 삽입하는 것이다. 나의 경우, A 프로젝트를 참고하여 B 프로젝트를 만들고 있었는데 분명 Additional Library Directories가 동일함에도 내 프로젝트 에서는 L..
DLL이 경로에 있음에도 DLLNotFound Exception이 뜬다면.. C# 프로그램에서 C++로 작성된 DLL 파일을 로드하려했는데(DllImport) DllNotFoundException 오류가 발생하였다. 찾아보니 C#에서 C++ DLL을 로드하기 위해선 1. C#의 빌드 형식과 C++ DLL의 빌드 형식이 맞아야 한다. 즉, x86이면 x86끼리, x64면 x64끼리 로드해야 한다는 얘기. 2. 같은 경로에 있어야 한다. 3. 함수 호출 스택 (cdecl 인지, stdcall 인지) 이 맞아야 한다. 즉, C++ DLL의 호출 스택이 cdecl이면 C# 에서도 cdecl로, stdcall 이면 stdcall로 받아주어야 한다. 4. C++ DLL에서 extern "C"를 선언해야 한다. 위와 같은 조건이 맞아야 한다. 위의 4가지를 다 해봤는데도 안되었다... 그러다..
EDITOR WARS #include #include #include #include using namespace std; struct NaiveDisjointSet { vector parent; NaiveDisjointSet(int n) : parent(n) { for (int i = 0; i < n; i++) parent[i] = i; } int find(int u) const { if (u == parent[u]) return u; return find(parent[u]); } void merge(int u, int v) { u = find(u); v = find(v); if (u == v) return; parent[u] = v; } }; struct OptimizedDisjointSet { vector parent,..
MEASURETIME (FENWICK TREE) #include #include using namespace std; struct FenwickTree { vector tree; FenwickTree(int n) : tree(n + 1) {} int sum(int pos) { ++pos; int ret = 0; while (pos > 0) { ret += tree[pos]; pos &= (pos - 1); } return ret; } void add(int pos, int val) { ++pos; while (pos > cn;..
MORDOR #include #include #include using namespace std; const int int_max = numeric_limits::max(); typedef struct DifficultyNode { int min, max; DifficultyNode() { min = int_max; max = 0; } DifficultyNode(int _min, int _max) : min(_min), max(_max) {} } DifficultyNode; typedef struct DifficultyQuery { vector querySource; int n; DifficultyQuery(vector &array){ n = array.size(); querySource.resize(n * 4); ..
RUNNINGMEDIAN #include #include #include using namespace std; typedef int KeyType; // 이 함수들은 문제 풀 때 쓰이진 않지만 (C++ STL 의 priority_queue를 대신 사용) // 기왕 구현했으니 넣어둠 void push_heap(vector &heap, KeyType key); void pop_heap(vector &heap); void swap(int *a, int *b); typedef struct Rng { int seed, a, b; Rng(int _a, int _b) : a(_a), b(_b) { seed = 1983; } int next() { int prevSeed = seed; seed = (seed * (long long)a + b)..
TREAP_INSERTION #include #include using namespace std; typedef int KeyType; typedef struct Node { KeyType key; int priority, size; Node *left, *right; Node(const KeyType& _key) : key(_key), priority(rand()), size(1), left(nullptr), right(nullptr) {} void setLeft(Node* newLeft) { left = newLeft; calcSize(); } void setRight(Node* newRight) { right = newRight; calcSize(); } void calcSize() { size = 1; if (left) si..
FORTRESS #include #include #include using namespace std; typedef struct Node { int x, y, r; int idx; vector childs; Node(int _x, int _y, int _r, int _idx) : x(_x), y(_y), r(_r), idx(_idx) {} } Node; void getLongestLeafPath(Node* const root); int height(Node* const root); bool compareNode(Node* a, Node* b); void PrintPrefix(Node* const root); void Insert(Node* const root, Node* const node); bool IsInside(..