XCX's Blog


  • 首页

  • 归档

  • 标签

Git 使用指南

发表于 2023-02-05

安装 Git

Git 下载地址

安装一路 Next 就行。

注册 GitHub

注册链接

注意:在接下来的步骤中,<username> 表示用户名,<email> 表示注册时使用的电子邮件。

配置 Git

新建一个文件夹,例如 git-study。

在这个文件夹中,右键点击,找到 Git Bash Here,单击打开。

git-bash

在命令行里输入:

1
2
git config --global user.name "<username>"
git config --global user.email "<email>"

git-config-username-and-email

创建 GitHub SSH Key

参见这篇文章。

Try to use Git!

创建代码仓库

在 GitHub 上新建一个代码仓库(repository)。

在本地新建一个空仓库

打开 Git Bash,输入 git init; git branch -M main。

git-init-repository

编写一些文件(如 README.md),并 Push 到 GitHub 原仓库

编写 README

1
echo "# example-repo" >> README.md

Commit

1
2
git add README.md
git commit -m "Create README.md"

Setup remote repository

1
git remote add origin git@github.com:xcx0902/example-repo.git

Push to remote repository

1
git push -u origin main

Overall

1
2
3
4
5
echo "# example-repo" >> README.md
git add README.md
git commit -m "Create README.md"
git remote add origin git@github.com:xcx0902/example-repo.git
git push -u origin main

git-commit-and-push

Game suggestion - Local Generals.io

发表于 2023-02-04

Description

Project URL: https://github.com/xcx0902/lgen

This is a simple localized generals.io game. You can download the latest version here.

The right way to start the game

First, run the downloaded exe file. If you can’t run it, please download the full project (source code) here, and complie src/main.cpp with g++ -std=c++14.

How to play

Start the game

Press 0 to start the game. The game rules is the same as generals.io.

Draw a map

Press 1 to draw a map. The map will save as map/<mapname>.lgmap.

Watch a saved replay

Press 2 to watch a saved replay. It may take a few seconds to load the replay.

View the usage of this program

Press 3 to view the usage of this program (show this page).

View our GitHub project

Press Enter to view our GitHub project (mentioned above).

GitHub SSH Key 使用指南

发表于 2023-02-04

生成 SSH Key

打开 Git Bash,输入 ssh-keygen -t rsa -C "<your-email>",配置均使用默认配置(直接回车)。

generate

检查是否生成成功

打开 C:\Users\<Windows.Username>\.ssh\ 文件夹,如果里面有 id_rsa 和 id_rsa.pub 两个文件,即为成功。

添加 Key

打开 id_rsa.pub,复制里面的内容。打开 GitHub SSH Key,按照下面的指示填写。

add-new-key

Hexo 博客搭建指南

发表于 2023-02-04

软件安装

  1. Git(镜像)
  2. Node.js(镜像)

检查配置

启动 cmd,运行 git --version,node -v,npm -v。出现以下结果即为安装成功(版本号可能不同)。

check-installation

安装 Hexo

新建一个文件夹,名称、位置随便(最好在非系统盘)。

进入该文件夹,右击打开 Git Bash,执行如下命令。

1
2
3
4
npm install hexo-cli -g
hexo init .
npm install
hexo server

打开浏览器,访问 localhost:4000,如果看到博客界面,即为搭建成功。如果在最后一步提示:

1
2
FATAL Port 4000 has been used. Try other port instead.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html

表示端口 4000 已占用,运行 hexo server -p <port-number> 即可,其中 <port-number> 为自定义端口号,另外在访问时也要访问 localhost:<port-number>。

新建文章

在 Hexo 根文件夹运行 hexo new "<post-name>" 即可,其中 <post-name> 为文章名(后续可修改)。此时在 source/_post 文件夹下会多出一个 Markdown 文件,编辑它即可。

注意:文件头部用 --- 包含的内容不要删除,它是文章的定义,例如本篇文章的头部就是:

1
2
3
4
5
6
7
8
---
title: Hexo 博客搭建指南
date: 2023-02-04 13:28:20
tags:
- Hexo
- GitHub
- Instruction
---

部署到静态网页

首先需要一个 GitHub 账号,没有的需要注册一个。

新建一个仓库,名称必须为 <username>.github.io,其中 <username> 为你的用户名。

然后,在 Hexo 根文件夹下的 _config.yml 中添加如下内容。

1
2
3
4
deploy:
type: git
repository: git@github.com:<username>/<username>.github.io.git
branch: main

注意:这里需要有 GitHub SSH Key,没有的请参照这篇文章。

最后,运行 hexo generate && hexo deploy 即可。

建议:在部署前最好先在本地浏览一下(hexo generate && hexo server),以免出现问题。

使用 Netlify 加速

众所周知,GitHub Pages 加载很慢,有时甚至根本加载不出来。我们可以通过使用 Netlify 进行加速。下面是两张对比图。

加速前:
github-speed

加速后:
netlify-speed

首先注册 Netlify(使用 GitHub 账号注册)。然后添加站点:

netlify-add-site

netlify-import-site-from-github

netlify-import-site-select-repo

netlify-deploy-site

等待部署完成后,即可获得一个随机二级域名供访问(见网页提示)。如需更改这个二级域名,按照以下步骤进行即可。

netlify-set-domain-1

netlify-set-domain-2

netlify-set-domain-3

迁移

去除 .gitignore 中的某些条目

在 Hexo 根文件夹有一个 .gitignore 文件,初始内容为:

1
2
3
4
5
6
7
8
.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/
_multiconfig.yml

将其改为:

1
2
3
4
5
.DS_Store
*.log
public/
.deploy*/
_multiconfig.yml

新建博客源码仓库

新建一个仓库,名称随便(最好为 blogSource,方便识别)。

在 Hexo 根文件夹下运行(Git Bash):

1
2
3
4
git init
git remote add origin git@github.com:<username>/<blogSource-repo>.git
# <username> 用户名,<blogSource-repo> 源码仓库(刚才创建的)
echo "git add . && git commit -m 'Update blog source' && git push -u origin main" > updsource.sh

之后,在更新博客时,运行 ./updsource.sh 即可上传到源码仓库。

迁移

同样先得安装必要软件(即 Git 与 Node.js),创建博客根目录,然后运行:

1
2
npm install hexo-cli -g
git clone git@github.com:<username>/<blogSource-repo>.git

就完成了迁移。

Attachments Test

发表于 2023-01-19

Attachment

If you see this:

1
Attachment enabled sucesscully.

It means that the attachment feature is enabled successfully.

Code Test

1
2
3
4
5
6
7
#include <bits/stdc++.h>
using namespace std;

int main() {
// Your code goes here
return 0;
}

Zip Test

1
2
3
|
|-- 1.txt
|-- 2.cpp

Images Test

发表于 2023-01-19

XCX Round 2 Overall Editorial

发表于 2023-01-19

Problem A

概率与期望 + DP

令 $f_i$ 为 $i$ 张卡的合成概率,显然

初值:$f_5 = a\%$

答案:$f_b \times 100$

暴力转移即可。

时间复杂度:$O(b)$ per test case

空间复杂度:$O(b)$ per test case

Problem B

高精度 + 二分

二分每一位的值,并使用高精度乘法判断即可。

令 $T = 120$,即保留的位数。

时间复杂度:$O(\log_2 x + T \times \log_2 10 \times T^2)$ per test case

空间复杂度:$O(T)$ per test case

Problem C

01 Trie 树

令 $d_i$ 为点 $i$ 到树根的权值异或和,则 $f(i, j) = d_i \oplus d_j$。

只需做一个 Trie 树,将 $d$ 数组所有值加入,然后对于每个 $d_i$,求 Trie 树中与其异或最大的值即可。

时间复杂度:$O(n \log_2 \max_{w_i})$

Problem D

模拟

由于是大模拟,不再赘述。细节详见代码。

Problem E

组合数学 + 二项式定理


$20$ pts:暴力(不再赘述)


$50$ pts:

前置知识:二项式定理:

然后,我们发现原来的式子中就有这个东西,于是把它提取出来后得:

可以发现,上面这个式子与 $j, k$ 无关,只与 $j+k$ 有关。

然后,我们就可以枚举 $j+k$,将 $O(n^3)$ 优化为 $O(n^2)$。

新式子如下:

其中,$T = n-|j-n-1|$。

原因如下:

当 $j=2$ 时,$1$ 次计算,

当 $j=3$ 时,$2$ 次计算,

当 $j=n+1$ 时,$n$ 次计算,

当 $j=2 \times n - 1$ 时,$2$ 次计算,

当 $j=2 \times n$ 时,$1$ 次计算。


$100$ pts:

我们可以交换式子的两层循环,答案不变,即为

我们需要快速计算

将该式乘 $j$ 再减去该式,得到

即

带入原式,得到

由于 $10^9+7$ 是质数,所以求出 $j-1$ 的逆元即可。

时间复杂度:$O(n^2)$

How to use GitHub Actions

发表于 2023-01-18

GitHub Actions is designed to run your jobs in a free runner from a repository.

The jobs are like “publish your own blog” or “build docker” and so on.

How to use

First, you need a GitHub account. Register a GitHub account at here.

Next, create a repository here. You can name the repository with any name you want.

Then, create a file in the repository that you created called .github/workflows/<name>.[yml/yaml]. Fill it with the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
name: <workflow_name>

on:
push: # You want to run the workflow when there's a push operation in the following branches
branches: ["main", ...]
pull_request: # You want to run the workflow when there's a pull_request operation in the following branches
branches: ["main", ...]
workflow_dispatch # You want to run the workflow manually at the action page

jobs:
build:
runs_on: [ubuntu-latest/windows-latest/macos-latest] # Filled with the machine type you want to use
steps:
- uses: actions/checkout@v3 # clone the repository to runner's work directory
- name: <step_name>
run: <command_you_want_to_run>
- name: <step_name>
run: |
<multi_commands>
...
deploy:
...
...

If you set it automatically run after push or pull request operations, you’re already done. If you set workflow_dispatch, go to Action page, then you can find your defined workflow <workflow_name> in the left sidebar. Click it, then choose Run workflow and click Run workflow to run the workflow.

Latex Test

发表于 2023-01-18

$123$

$\text{123, CURELMUS}$

$\mathtt{123, CURELMUS}$

$x^{x^{x^x}}$

$\frac{x}{y} \times \frac{z}{w}$

Hello World

发表于 2023-01-18

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

10 日志
10 标签
© 2023 xcx0902
由 Hexo 强力驱动
主题 - NexT.Pisces