Skip to content

Instantly share code, notes, and snippets.

View usk83's full-sized avatar

Yusuke Takahashi usk83

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
#include <ctype.h>
CSEG SEGMENT
ASSUME CS:CSEG, DS:CSEG, ES:CSEG
ORG 100H
START:
;dsはVRAMのアドレス、esは保存メモリのアドレスに固定
mov ax, 0b800h ;VRAMの先頭アドレス
mov ds, ax
mov ax, 9000h ;保存メモリの先頭アドレス
mov es, ax
@usk83
usk83 / TheEndOfTheMonth.ics
Created May 1, 2018 02:37 — forked from honda0510/TheEndOfTheMonth.ics
Google カレンダーに月末の予定を追加するiCalendarファイル
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Asia/Tokyo
BEGIN:STANDARD
TZOFFSETFROM:+0900
TZOFFSETTO:+0900
TZNAME:JST
@usk83
usk83 / Topic2.swift
Created February 24, 2020 22:50
Find the substring pattern of length M in a text of length N.
import Foundation
func findSubstring(_ text: String, _ pattern: String) -> String.Index? {
return findSubstringBM(text, pattern)
}
func findSubstringBM(_ text: String, _ pattern: String) -> String.Index? {
let pLength = pattern.count
let tLength = text.count
var table = [Character:Int]()
@usk83
usk83 / LowestCommonAncestor.swift
Last active February 27, 2020 00:36
LCA (Lowest Common Ancestor)
import Foundation
func readTree() -> [[Int]] {
let n = Int(readLine()!)!
var tree = [[Int]](repeating: [Int](), count: n + 1)
for _ in 1..<n {
let nodes = readLine()!.split(separator: " ").map { Int($0)! }
tree[nodes[0]].append(nodes[1])
tree[nodes[1]].append(nodes[0])
}
@usk83
usk83 / UF.swift
Last active February 27, 2020 23:56
Union-Find (Disjoint sets)
//
// UF.swift
// SwiftAlgorithmsDataStructures
//
// Created by Derrick Park on 2/24/20.
// Copyright © 2020 Derrick Park. All rights reserved.
//
import Foundation
@usk83
usk83 / SushiRestaurantReviews.swift
Last active February 29, 2020 00:55
Sushi Restaurant Reviews
import Foundation
func readInput() -> ([[Int]], Set<Int>) {
let meta = readLine()!.split(separator: " ").map { Int($0)! }
var input = ([[Int]](repeating: [Int](), count: meta[0]), Set<Int>())
let realNodes = readLine()!.split(separator: " ").map { Int($0)! }
input.1 = Set<Int>(realNodes)
for _ in 0..<meta[0] - 1 {
@usk83
usk83 / CyclicPermutation.swift
Created March 2, 2020 20:22
Problem Set 2 (Graph)
import Foundation
/*
* DFS
* - Time: O(N)
* - Space: O(N)
*/
func solveCyclicPermutationByDFS() {
let t = Int(readLine()!)!
for _ in 0..<t {
@usk83
usk83 / 207_CourseSchedule.swift
Last active March 6, 2020 01:05
Problem Set 6 (DAG + Topological Sort)
class Solution {
func canFinish(_ n: Int, _ edges: [[Int]]) -> Bool {
var inDegrees = [Int](repeating: 0, count: n)
var graph = [[Int]](repeating: [Int](), count: n)
for edge in edges {
inDegrees[edge[0]] += 1
graph[edge[1]].append(edge[0])
}
var initialVs = [Int]()
@usk83
usk83 / 1029-TwoCityScheduling.swift
Created March 10, 2020 19:37
Problem Set 7 (Greedy Algorithms)
/*
* > Runtime: 16 ms, faster than 100.00%
* > Memory Usage: 21.2 MB, less than 100.00%
*/
class Solution {
func twoCitySchedCost(_ costs: [[Int]]) -> Int {
var left = [Int]()
left.reserveCapacity(costs.count >> 1)
var right = [Int]()
right.reserveCapacity(costs.count >> 1)