목록자료구조 (7)
레야몬
#include #include #include #include #define MAX_BAG 300001 #define LOOP(i, n) for(int i=1; i> N >> K; LOOP(i, N) { int M, V; cin >> M >> V; jew.push_back({M, V}); } LOOP(i, K) cin >> b_wei[i]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); input(); sort(b_wei+1, b_wei+K+1); //가방 오름차순 정렬 sort(jew.begin(), jew.end()); //보석의 무게로 오름차순 정렬 int id=0; LOOP(i, K) { int C ..
#include #define MAX_VERTEX 'Z'+1 using namespace std; pair tr[MAX_VERTEX]; //이진 트리 int N; //이진 트리의 노드의 개수 void f(char Node) { cout > b; tr[u] = {v, b}; //왼쪽 노드, 오른쪽 노드 } f('A'); cout
#include #include #include #include using namespace std; priority_queue max_pq; //최대 트리 int N, x; //연산의 개수, 정수 x int main() { ios_base::sync_with_stdio(false); //동기화 cin.tie(NULL); cout.tie(NULL); cin >> N; for(int i=0; i> x; if(!x) { if(max_pq.empty()) //큐가 비어있을 경우 0 출력 cout
결과적으론 나는 이 문제를 푸는 데 실패하였고 더 이상 C언어로 알고리즘 코드를 짜는 것은 힘들다고 생각하였다. 그래서 C언어에서 C++언어로 바꾸기로 하였고 코드는 다른 사람의 블로그에서 가져왔다. 그대로 가져왔고 내가 짠 코드는 절대 아니다. #include #include #include #include #include using namespace std; priority_queue min_pq; priority_queue max_pq; map dict; int T, k, n; char c; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> T; while (T) { while (!min_pq.em..
#include #include #define MAX_VERTICES 101 int cnt; typedef struct GraphType { int n; int adj_mat[MAX_VERTICES][MAX_VERTICES]; } GraphType; void init(GraphType *g) { int r, c; g->n=0; for(r=0; radj_mat[start][end]=1; g->adj_mat[end][start]=1; } void cnt_vertex(int u, GraphType *g) { int i, j; for(i=1; in; i++) { if(g->adj_mat[u][i]) { for(j=1; jn; j++) g->adj_mat[j][i]=0; g->adj_mat[u][i]=0, g->..
#include #define SWAP(x, y) do{int tmp; tmp=x; x=y; y=tmp;}while(0) #define MAX_N 100000 typedef struct _heap { //힙 구조체 int arr[MAX_N]; int size; } heap; heap h; void insert(heap* hp, int data) //힙 넣기 { int here = ++hp->size; while((here!=1) && (dataarr[here/2])) { hp->arr[here] = hp->arr[here/2]; here/=2; } hp->arr[here] = data; } int deleteData(heap *hp) //힙 꺼내기 { if(!hp->size) return 0; int r..
#include #include #define MAX_QUEUE_SIZE 100000 int memo[200000]; typedef struct _Loc { int s; int cnt; } Loc; typedef struct _Queue //큐 구현 { int front; int rear; Loc data[MAX_QUEUE_SIZE]; } Queue; void init_queue(Queue *q) { q->front=q->rear=-1; } void enqueue(Queue *q, Loc l) { q->data[(++q->rear)%MAX_QUEUE_SIZE]=l; } Loc dequeue(Queue *q) { return q->data[(++q->front)%MAX_QUEUE_SIZE]; } int m..