Skip to content

Instantly share code, notes, and snippets.

View magiskboy's full-sized avatar

Nguyễn Khắc Thành magiskboy

View GitHub Profile
@magiskboy
magiskboy / shortest_path.cpp
Created May 2, 2021 01:15
Dunamic programming
#include <bits/stdc++.h>
using namespace std;
/*
* Cho đồ thị vô hướng G có N đỉnh (N≤1000) và các cạnh có trọng số dương.
* Tìm đường đi ngắn nhất từ đỉnh 1 đến đỉnh N hoặc thông báo không tồn tại đường đi.
* Simple input
* 5
* 0 1 1 5 5
#include <bits/stdc++.h>
using namespace std;
int v[100];
int n;
void gen(int i) {
if (i == n) {
for (int j = 0; j < n; ++j) cout << v[j] << " ";
@magiskboy
magiskboy / bst.py
Last active April 11, 2021 23:45
Datastructure
class BST:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
@classmethod
def from_arr(cls, arr):
root = BST(arr.pop(0))
for x in arr:

Ý tưởng

Do yêu cầu dữ liệu đầu vào vượt quá khả năng lưu trữ của bộ nhớ trong, ta sẽ sử dụng bộ nhớ ngoài để lưu trữ thông tin trong quá trình sắp xếp

Ta sẽ sử dụng các file được lưu trên đĩa như những mảng trong bộ nhớ trong.

Các file có đặc điểm khá giống Linked List

  • thuận tiện cho việc truy cập tuần tự
  • bất tiện cho truy cập ngẫu nhiên
@magiskboy
magiskboy / bai1.py
Created April 3, 2021 06:23
AIMESOFT test
class Node:
def __init__(self, value, next):
self.value = value
self.next = next
def solve(arr):
curr = arr
while curr:
print(curr.value, end=' -> ')
from queue import LifoQueue as Stack
def move_disk(n_disk, source, target, temp):
if n_disk == 1:
print(f'Move disk from {source} to {target}')
else:
move_disk(n_disk-1, source, temp, target)
move_disk(1, source, target, temp)
@magiskboy
magiskboy / fibonacci.cpp
Last active January 31, 2021 13:43
Fast and big fibonacci number
#include<iostream>
#include<cstdlib>
using namespace std;
string add(string a, string b) {
size_t la = a.size(), lb = b.size();
if (la > lb) {
b.insert(0, la-lb, '0');
}
from queue import Queue
class SystemCall:
__slots__ = ('sched', 'target')
def handle(self):
pass
import java.util.*;
public class Balanced {
static char[][] TERMS = {{'(', ')'}, {'[', ']'}, {'{', '}'}};
static boolean match(char openTerm, char closeTerm) {
for (char[] c : TERMS) {
if (c[0] == openTerm) {
return c[1] == closeTerm;
@magiskboy
magiskboy / get-lucumr.pocco.py
Created September 4, 2020 23:44
Clone lucumr.pocco.org
import asyncio
import sys
import httpx
from bs4 import BeautifulSoup
site = 'https://lucumr.pocoo.org'
def get_next_page_url(page):