Gorio Tech Blog search

Github blog 수식 입력 방법

|

이 글에서는 수식 입력방식을 설명한다.

참조: stackexchange.com


수식 입력은

inline style: $ \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $

$ \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $

display style: $$ \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $$

[\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}]

로 한다.

참고: newline은 display style에서만 유효하다.

$$ \begin{eqnarray} a^2 + b^2 &=& c^2 \\ &=& 5 \end{eqnarray} $$

[\begin{eqnarray} a^2 + b^2 &=& c^2 \ &=& 5 \end{eqnarray}]

$$ \Delta s = \Biggl\{ \begin{matrix} A \\ B \end{matrix} $$

[\Delta s = \Biggl{ \begin{matrix} A+B \ C \end{matrix}]

Equation Code Display
NewLine \\ $ \ $
Greek small Letters 1 \alpha, \beta, \gamma, \delta, \epsilon, \varepsilon, \zeta, \eta, \theta, \vartheta, \iota, \kappa, \lambda, \mu $ \alpha, \beta, \gamma, \delta, \epsilon, \varepsilon, \zeta, \eta, \theta, \vartheta, \iota, \kappa, \lambda, \mu $
Greek small Letters 2 \nu, \xi, \pi, \rho, \varrho, \sigma, \tau, \upsilon, \phi, \varphi, \chi, \psi, \omega $ \nu, \xi, \pi, \rho, \varrho, \sigma, \tau, \upsilon, \phi, \varphi, \chi, \psi, \omega $
Greek Capital Letters \Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi, \Sigma, \Upsilon, \Phi, \Psi, \Omega $ \Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi, \Sigma, \Upsilon, \Phi, \Psi, \Omega $
Super/subscripts x_i^2, x_{i^2}, \log_2 x, 10^{10}, x^{y^z} $ x_i^2, x_{i^2}, \log_2 x, 10^{10}, x^{y^z} $
Parentheses 1 (\frac{1}{2}), \left(\frac{1}{2}\right) $ (\frac{1}{2}), \left(\frac{1}{2}\right) $
Parentheses 2 (x) {x} [x] |x| \vert x \vert \Vert x \Vert $ (x) {x} [x] |x| \vert x \vert \Vert x \Vert $
Parentheses 3 \langle x \rangle \lceil x \rceil \lfloor x \rfloor $ \langle x \rangle \lceil x \rceil \lfloor x \rfloor $
Parentheses 4 \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) $ \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) $
Parentheses 5 \Biggl{\biggl{\Bigl{\bigl{ \lbrace x \rbrace \bigr}\Bigr}\biggr}\Biggr} $ \Biggl{\biggl{\Bigl{\bigl{ \lbrace x \rbrace \bigr}\Bigr}\biggr}\Biggr} $
Parentheses 6 \Biggl[\biggl[\Bigl[\bigl[[x]\bigr]\Bigr]\biggr]\Biggr] $ \Biggl[\biggl[\Bigl[\bigl[[x]\bigr]\Bigr]\biggr]\Biggr] $
Combinations {n+1 \choose 2k} , \binom{n+1}{2k} $ {n+1 \choose 2k} , \binom{n+1}{2k} $
Fraction \frac{(n^2+n)(2n+1)}{6}, {a+1\over b+1}, \cfrac{a}{b} $ \frac{(n^2+n)(2n+1)}{6}, {a+1\over b+1}, \cfrac{a}{b} $
Sigma \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $ \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $
Signs \infty \prod \int \bigcup \bigcap \iint \iiint \sqrt{x} $ \infty \prod \int \bigcup \bigcap \iint \iiint \sqrt{x} $
Special functions \lim_{x\to 0} \sin \max \ln \log $ \lim_{x\to 0} \sin \max \ln \log $
Matrix 1 \begin{matrix}a & b \\ c & d\end{matrix} $\begin{matrix}a & b \ c & d\end{matrix}$
Matrix 2 \begin{pmatrix}a & b & c \\ d & e & f \\ g \end{pmatrix} $\begin{pmatrix}a & b & c \ d & e & f \ g \end{pmatrix}$
Multi-lines \begin{eqnarray} a^2 + b^2 &=& c^2 \ &=& 5 \end{eqnarray} 표 위쪽 참조.
Inequality \lt \gt \le \leq \leqq \leqslant \ge \geq \geqq \geqslant \neq \gg \ll \ggg \lll $ \lt \gt \le \leq \leqq \leqslant \ge \geq \geqq \geqslant \neq \gg \ll \ggg \lll $
Approximate \approx \sim \simeq \cong \equiv \prec \lhd $ \approx \sim \simeq \cong \equiv \prec \lhd $
Set Inclusion \cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing $ \cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing $
Logic \land \lor \lnot \forall \exists \nexists \top \bot \vdash \vDash \complement $ \land \lor \lnot \forall \exists \nexists \top \bot \vdash \vDash \complement $
Operations 1 \times \div \pm \mp x \cdot y $ \times \div \pm \mp x \cdot y $
Operations 2 \star \ast \odot \oslash \oplus \otimes \Box \boxtimes \circ \bullet $ \star \ast \odot \oslash \oplus \otimes \Box \boxtimes \circ \bullet $
Arrows 1 \to \rightarrow \leftarrow \leftrightarrow \mapsto \longmapsto $ \to \rightarrow \leftarrow \leftrightarrow \mapsto \longmapsto $
Arrows 2 \leftharpoonup \rightharpoonup \leftharpoondown \rightharpoondown \rightleftharpoons $ \leftharpoonup \rightharpoonup \leftharpoondown \rightharpoondown \rightleftharpoons $
Arrows 3 \uparrow \downarrow \nearrow \searrow \swarrow \nwarrow $ \uparrow \downarrow \nearrow \searrow \swarrow \nwarrow $
Arrows 4 \Rightarrow \Leftarrow \Leftrightarrow \Uparrow \Downarrow \Updownarrow $ \Rightarrow \Leftarrow \Leftrightarrow \Uparrow \Downarrow \Updownarrow $
Modulo a\equiv b\pmod n $ a\equiv b\pmod n $
Ellipsis \ldots, \cdots $ \ldots, \cdots $
Transpose \intercal \top \mid $ \intercal \top \mid $
Spaces 1 \ 2 \quad 3 \qquad 4 $ 1 \ 2 \quad 3 \qquad 4 $
Accents \hat{x} \widehat{xy} \bar{x} \overline{xyz} \vec{x} \overrightarrow{xy} \overleftrightarrow{xy} \dot{x} \ddot{x} $ \hat{x} \widehat{xy} \bar{x} \overline{xyz} \vec{x} \overrightarrow{xy} \overleftrightarrow{xy} \dot{x} \ddot{x} $
Special Characters 1 \backslash \_ \lrace \rbrace $\backslash$ _ $\lbrace \rbrace$
Plain text \text{text…} $ \text{text…} $
Special Characters 2 \infty \aleph_0 \nabla \partial \Im \Re \surd \triangle \square \blacksquare $ \infty \aleph_0 \nabla \partial \Im \Re \surd \triangle \square \blacksquare $
Fonts l \ell \it{l} \boldsymbol{l} \pmb{l} $ l \quad \ell \quad \it{l} \quad \boldsymbol{l} \quad \pmb{l} $
mathbb \mathbb{A} $ \mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathbb \mathbb{a} $ \mathbb{abcdefghijklmnopqrstuvwxyz} $
mathbf \mathbf{A} $ \mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathbf \mathbf{a} $ \mathbf{abcdefghijklmnopqrstuvwxyz} $
mathtt \mathtt{A} $ \mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathtt \mathtt{a} $ \mathtt{abcdefghijklmnopqrstuvwxyz} $
mathrm \mathrm{A} $ \mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathrm \mathrm{a} $ \mathrm{abcdefghijklmnopqrstuvwxyz} $
mathsf \mathsf{A} $ \mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathsf \mathsf{a} $ \mathsf{abcdefghijklmnopqrstuvwxyz} $
mathcal \mathcal{A} $ \mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathcal \mathcal{a} $ \mathcal{abcdefghijklmnopqrstuvwxyz} $
mathscr \mathscr{A} $ \mathscr{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathscr \mathscr{a} $ \mathscr{abcdefghijklmnopqrstuvwxyz} $
mathfrak \mathfrak{A} $ \mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ} $
mathfrak \mathfrak{a} $ \mathfrak{abcdefghijklmnopqrstuvwxyz} $

Mathjax 참고

Comment  Read more

Stack(스택)

|

참조

분류 URL
문제 스택, 괄호
응용 문제 스포일러 문제
이 글에서 설명하는 라이브러리 std::stack

개요

시간복잡도: $ O(M) $

공간복잡도: $ O(N) $

  • N은 원소의 수, M은 연산의 수이다.
  • 스택 자체는 알고리즘이 아닌 자료구조이지만, 스택을 쓰는 경우 복잡도는 위와 같이 나온다.

이 글에서는 스택(stack)이라고 하는 자료구조와, 이를 활용한 문제들을 살펴볼 것이다.

스택은 간단하면서도 매우 유용한 자료구조이다. 여러분의 실생활에서도 자주 볼 수 있는 개념이다.
그리고 알고리즘으로 적용하기에도 쉽다. 그럼 스택은 무엇인가?


Stack(스택)

스택(stack)의 사전적 의미는 더미(무더기)이다.

스택은 다음 그림으로 설명된다.

Stack

책상 위에 책을 몇 권 쌓는 것과 같다. 1번 책을 쌓고, 2번 책을 쌓고, … , 6번 책까지 쌓았다고 하자.
그리고 책을 한 권을 집는다고 치자. 그러면 여러분은 (정상적이라면) 몇 번 책을 집겠는가?
사서 고생하는 사람이 아니라면 굳이 아래쪽 책을 힘들게 빼진 않을 것이다. 즉, 6번 책을 뺄 것이다. 위의 그림과 갈다.
첫 번째 pop(책을 빼는 것) 연산은 가장 마지막에 들어온 6번부터 행해진다.

이것을 Last-In-First-Out이라 부른다. 즉 가장 나중에 들어온 것이 제일 먼저 나간다는 의미이다.
이것이 스택의 전부이다. 그리고 C++의 STL에는 이것이 친절히 구현되어 있다. 다음에서 살펴보자.

std::stack 사용법

Include

우선 include를 해야 한다. 특별히 큰 프로젝트에서 쓰는 것이 아니라면, std::를 매번 쓰기 귀찮으니 namespace도 써 주자.

#include <stack>

using namespace std;

선언

stack은 generic으로 구현된 template이다. 즉, stack에 들어갈 데이터 타입을 정해야 한다.
보통 int나 char 등을 사용하게 될 것이다. 물론 기본형 뿐만 아니라 사용자 정의 타입도 가능하다.

stack<int> st; // 현재 비어 있다.
// stack<char> st_c;
// stack<dot_2d> st_person; // dot_2d는 알아서 정의하시길...

push(e)

스택에 무언가를 집어넣는(push) 연산이다. e는 집어넣을 원소이다.

st.push(10);  // 10
st.push(20);  // 10 20
st.push(30);  // 10 20 30
st.push(777); // 10 20 30 777

size()

스택의 현재 size를 반환한다. 몇 개나 들어 있는지 알고 싶을 때 쓰면 된다.

printf("size: %d\n", st.size());  // size: 4
st.push(999);
printf("size: %d\n", st.size());  // size: 5

top()

스택의 맨 위 원소를 반환한다. 스택에서는 맨 위의 것만 빼낼 수 있다. 다른 원소에는 접근이 불가능하다.
물론 스택을 직접 구현한다면 접근 가능하게 할 수도 있지만, 스택을 쓰는 데 그렇게 할 이유가..?

int e = st.top();
printf("top: %d\n", e);   // top: 999

pop()

스택의 맨 위 원소를 제거한다. 책을 하나 가져갔다고 생각하면 된다.
반환값이 void이므로 리턴값으로 top 값을 알아낼 수는 없다.
또, 비어 있는데 pop을 수행하려고 하면 런타임 에러를 발생시킨다.

st.pop(); // 999가 제거됨
for (int i = 0; i < 3; i++)
    st.pop(); 
// 777, 30, 20이 차례로 제거됨

empty()

스택이 비었는지를 검사한다. size() == 0 구문으로 체크할 수도 있지만, 이쪽이 더 직관적이다. 그리고 생각보다 자주 쓰게 된다.

if (st.empty())
    printf("stack is empty, 1\n");
st.pop();   // 10이 제거됨
if (st.empty())
    printf("stack is empty, 2\n");

// stack is empty, 2

emplace(e)

STL에서 emplace는 생성자를 호출하면서 push(혹은 push_back)하는 것과 동일하다.
이 기능은 stack에 기본형 말고 dot_2d와 같은 사용자 정의 함수나 생성자 호출이 필요한 데이터 타입을 넣었을 때 필요하다.
int와 같은 기본형을 넣을 때는 별 차이가 없다.

st.emplace(-3);
printf("top: %d\n", st.top());  // top: -3

swap(another_stack)

같은 데이터 타입을 담고 있는 다른 스택과 원소 전체를 swap한다.

stack<int> another_st;
st.swap(another_st);
if (st.empty())
    printf("stack is empty, 3\n");
// stack is empty, 3

스택은 사실상 이게 전부이다. 그리고 생각보다 많은 문제를 풀 수 있다.
물론 대부분은 너무 뻔히 풀이가 스택이라는 것이 보이지만, 안 그런 것도 있다(스포일러 문제 참조)

문제 풀이

BOJ 10828(스택)

문제: 스택

풀이: BOJ 10828(스택) 문제 풀이

BOJ 09012(괄호)

문제: 괄호

풀이: BOJ 09012(괄호) 문제 풀이

스포일러 문제

문제: 스포일러 문제

풀이: 스포일러 풀이

Comment  Read more