Skip to content

Instantly share code, notes, and snippets.

@amoshyc
amoshyc / poj3255.md
Last active September 25, 2022 12:35
Poj 3255: Roadblocks

Poj 3255: Roadblocks

分析

求次短路徑……修改 Dijkstra,不只記錄到各點的最短距離(d[i]),還記錄次短距離(sd[i]

實作上有幾點要注意( 不確定這樣想對不對… ):

@amoshyc
amoshyc / nim_game_classic.md
Last active April 20, 2021 16:52
Nim Game Strategy

Nim Game

文章節錄、翻譯、改寫自

玩法

  1. 共有三堆石頭,分別有 3, 4, 5 顆。
  2. 只有兩個玩家。兩個玩家輪流拿石頭,每次拿石頭可以從三堆中任意一堆拿走不限數量的石頭,但不可以一顆石頭都不拿。
  3. 贏家為拿走最後一個石頭的人。
def boxes_iou(boxesA, boxesB):
boxesA = boxesA.astype(float)
boxesB = boxesB.astype(float)
boxesA[:, 2:] += boxesA[:, :2]
boxesB[:, 2:] += boxesB[:, :2]
N, M = len(boxesA), len(boxesB)
boxesA = np.broadcast_to(boxesA.reshape(N, 1, 4), (N, M, 4))
boxesB = np.broadcast_to(boxesB.reshape(1, M, 4), (N, M, 4))
x1 = np.maximum(boxesA[..., 0], boxesB[..., 0])
@amoshyc
amoshyc / binary_search_tutorial.md
Last active April 6, 2020 18:17
二分搜教學

二分搜:講解

以下出現 A[l, r] 代表 A 陣列中 [l, r] 這個區間。 同理 A[l, r) 代表 A 陣列中 [l, r) 這個區間。

以下範例皆不處理 IO 的部份,都假設變數皆已被讀入。

基本使用

大一時學過,我們可以用二分搜在一個單調(遞增或遞減)的陣列中,尋找某個值在哪裡:

#include "../Externals/Include/Include.h"
#include "Object.hpp"
#define sz(x) (int(x.size()))
using namespace glm;
using namespace std;
#define SHADOW_MAP_SIZE 2048
Object quad;
#version 410 core
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
out vec4 color;
in VS_OUT
{
#version 410
layout(location = 0) out vec4 fragColor;
uniform mat4 um4mv;
uniform mat4 um4p;
in VertexData
{
vec3 N; // eye space normal
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
@amoshyc
amoshyc / poj1182.md
Last active December 12, 2017 15:34
Poj 1182: 食物鏈

Poj 1182: 食物鏈

分析

並查集經典題。 並查集要記得 init 啊


[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Mouse Button Remap
Comment=Exchanging Mouse Right & Middle Button
Exec=sh -c "xinput set-button-map $(xinput list --id-only 'pointer:Logitech USB Receiver') 1 3 2"
Terminal=false