Fork me on GitHub

blog

Hexo+Github免费搭建个人博客

效果浏览:我的博客

安装Git和Node.js

直接去GitNode.js官网下载,下载较简单,这里不赘述。

安装Hexo

命令行输入即可

1
npm install -g hexo-cli

Hexo初始化

新建一个文件夹,可名为Blog,方便后期管理,(不想要可删掉从来),进入文件夹目录下执行如下命令:

1
2
hexo init
npm install

运行成功后我们可以发现文件夹下新增了很多文件
其中含有_config.yml文件 ,这个文件就是网站主题的的配置文件,后面和github page关联和切换主题时,需要使用到。

生成静态文件和开启服务

1
2
hexo g
hexo s

ctrl+c 关闭本地服务器
打开 http://localhost:4000/ 即可看到你的博客雏形。
当然,这个只能在本地访问。

注册Github账号、新建一个仓库

注意:

  • 尾缀必须是github.io
  • 仓库名必须和Owner名一致

比如我的:

配置SSH

新建成功后,复制ssh,打开Blog文件夹目录下的_config.yml文件并按照以下更改:

1
2
3
4
deploy:
type: git
repository: 你的ssh
branch: master

创建文章

命令行执行

1
hexo new post <title>

默认在source/_post/新建一个markdown文件,用md语法编辑即可。

post 新建文章 /source/_posts/
draft 新建草稿 /source/_drafts/
page 新建页面(标签页,分类页等) /source/

更换主题

Hexo主题选择你喜欢的主题,在Blog目录下执行以下命令即可下载

1
git clone https://github.com/litten/hexo-theme-xxx.git themes/xxx

下载成功后即可发现themes文件夹中多了你刚下载的主题。

此时,需将Blog文件夹目录下的_config.yml文件中的theme 修改为theme: xxx,(需要注意的是冒号后有空格)

部署到Github

安装hexo的部署插件

1
npm install hexo-deployer-git --save

生成静态文件并部署

1
2
hexo g
hexo d

当然你也可以先hexo s浏览一下再部署。

这样你便拥有了属于你个人的博客
https://bingoyyj.github.io/

主题优化

配置categories和tags

命令行:

1
2
hexo new page "tags" 
hexo new page "categories"

编辑 /tags/index.md

1
2
type: "tags"
layout: "tags"

编辑/categories/index.md

1
2
type: "categories"
layout: "categories"

给文章分类和贴标签

1
2
3
4
5
6
7
8
9
10
---
title: test
date: 2020-04-07 17:19:57
categories:
- 博客教程
tags:
- Hexo
- Github
- 主题
---

一篇文章一般分类只一种,标签可多个。

本地图片

在source文件夹新建一个img文件夹存放图片,md文件用相对路径访问即可,如:

1
![](../img/1.jpg)

更多主题优化

更多主题优化在themes文件夹的_config.yml文件中,可根据个人喜好进行更改.

oj

潜规则

  • 输出后不留空格,下可留换行

经典算法

Minecraft

描述

Minecraft是一个几乎无所不能的沙盒游戏,玩家可以利用游戏内的各种资源进行创造,搭建自己的世界。
在Minecraft中,基本的建筑元素是边长为1个单位的立方体,Tony想用N个这种小立方体搭建一个长方体,并用他珍藏已久的贴纸对其进行装饰。如果一张贴纸可以贴满小立方体的一个面。那么,他需要用掉多少张贴纸呢?

输入

一个整数N,表示小明所拥有的小立方体的个数。N不会超过1000。

输出

一个整数,即小明最少用掉的贴纸有多少张。

输入样例

1
9

输出样例

1
30

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <climits>
using namespace std;
int main(){
int min=INT_MAX;
int n;
cin>>n;
for(int i=1;i<n;i++){
for(int j=1;j<n;j++){
if(n%(i*j)==0){
int k=n/(i*j),s;
s=2*(i*j+i*k+j*k);
if(s<min)
min=s;
}
}
}
cout<<min<<endl;
return 0;
}

线段相交

描述

每个线段是用平面上的两个点来描述,用结构体实现对于任意输入的2个线段,判断其是否相交。
提示:两点(x1,y1), (x2,y2) 间直线斜率是k=(y2-y1)/(x2-x1).

输入

判断次数和2条线段的x1、y1、x2、y2

输出

是否相交

输入样例

1
2
3
4
5
6
7
3 
1 5 2 9
1 3 2 4
5 6 7 8
5 7 7 7
2 5 1 0
9 4 2 9

输出样例

1
2
3
disjoint
intersect
disjoint

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
using namespace std;
struct point{
int x1,y1,x2,y2;
double k;
double b;
};
int main(){
int t;
cin>>t;
while(t--){
point point1,point2;
cin>>point1.x1>>point1.y1>>point1.x2>>point1.y2;
cin>>point2.x1>>point2.y1>>point2.x2>>point2.y2;
point1.k=float(point1.y2-point1.y1)/float(point1.x2-point1.x1);
point2.k=float(point2.y2-point2.y1)/float(point2.x2-point2.x1);
point1.b=point1.y1-point1.k*point1.x1;
point2.b=point2.y1-point2.k*point2.x1;
double y1,y2,y3,y4;
y1=point1.k*point2.x1+point1.b-point2.y1;
y2=point1.k*point2.x2+point1.b-point2.y2;
y3=point2.k*point1.x1+point2.b-point1.y1;
y4=point2.k*point1.x2+point2.b-point1.y2;
if(y1*y2<=0 && y3*y4<=0)
cout<<"intersect"<<endl;
else
cout<<"disjoint"<<endl;
}
return 0;
}

判断矩形是否重叠

描述

用具有x,y两个整型变量成员的结构类型SPoint来表示坐标点。用SRect结构类型来描述矩形,其中包含p1和p2两个SPoint成员分别表示矩形对角线上的两个点。
编写判断两个矩形是否重叠的函数。

输入

判断次数
矩形1的对角线顶点坐标x1、y1、x2、y2
矩形2的对角线顶点坐标x1、y1、x2、y2
……

输出

是否重叠

输入样例

1
2
3
4
5
6
7
3
1 5 2 9
1 3 2 4
5 6 7 8
5 7 7 7
2 5 1 0
9 4 2 9

输出样例

1
2
3
not overlapped
overlapped
overlapped

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
using namespace std;
struct SPoint{
int x1,y1,x2,y2;
};
int main(){
int t;
cin>>t;
while(t--){
SPoint p1,p2;
int t;
cin>>p1.x1>>p1.y1>>p1.x2>>p1.y2;
cin>>p2.x1>>p2.y1>>p2.x2>>p2.y2;
if(p1.x2<p1.x1){
t=p1.x1;
p1.x1=p1.x2;
p1.x2=t;
}
if(p1.y2>p1.y1){
t=p1.y1;
p1.y1=p1.y2;
p1.y2=t;
}
if(p2.x2<p2.x1){
t=p2.x1;
p2.x1=p2.x2;
p2.x2=t;
}
if(p2.y2>p2.y1){
t=p2.y1;
p2.y1=p2.y2;
p2.y2=t;
}
if(p1.y2>p2.y1 || p1.y1<p2.y2 || p1.x2<p2.x1 || p1.x1>p2.x2)
cout<<"not overlapped"<<endl;
else
cout<<"overlapped"<<endl;
}
return 0;
}

病人排队

描述

病人登记看病,编写一个程序,将登记的病人按照以下原则排出看病的先后顺序:
老年人(年龄 >= 60岁)比非老年人优先看病。
老年人按年龄从大到小的顺序看病,年龄相同的按登记的先后顺序排序。
非老年人按登记的先后顺序看病。

输入

第1行,输入一个小于100的正整数,表示病人的个数;
后面按照病人登记的先后顺序,每行输入一个病人的信息,包括:一个长度小于10的字符串表示病>人的ID(每个病人的ID各不相同且只含数字和字母),一个整数表示病人的年龄,中间用单个空格>隔开。

输出

按排好的看病顺序输出病人的ID,每行一个。

输入样例

1
2
3
4
5
6
5
021075 40
004003 15
010158 67
021033 75
102012 30

输出样例

1
2
3
4
5
021033
010158
021075
004003
102012

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
struct message{
string id;
int age{};
};
int main(){
int n;
cin>>n;
auto *p=new message[n];
int x=0,y=0;
message old[100];
message young[100];
for(int i=0;i<n;i++){
cin>>p[i].id>>p[i].age;
if(p[i].age>=60){
old[x]=p[i];
x++;
}
else{
young[y]=p[i];
y++;
}
}
//冒泡排序,不可用选择排序
for(int i=0;i<x-1;i++){
for(int j=0;j<x-1-i;j++){
if(old[j+1].age>old[j].age){
message t=old[j];
old[j]=old[j+1];
old[j+1]=t;
}
}
}
for(int i=0;i<x;i++){
cout<<old[i].id<<endl;
}
for(int i=0;i<y;i++){
cout<<young[i].id<<endl;
}
delete []p;
return 0;
}

C++

链表

创建

1
2
3
4
5
6
7
8
9
struct Node{
int data;
Node *next;
};
Node *head,*tail;
head=new Node;
head->data=0;
head->next=nullptr;
tail=head;

输入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int num;
cin>>num;
Node *head,*pnew,*tail;
head=new Node;
head->data=num;
head->next=nullptr;
tail=head;
while(num--){
int data;
cin>>data;
pnew=new Node;
pnew->data=data;
pnew->next=nullptr;
tail->next=pnew;
tail=pnew;
}

输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void show(Node *head);

show(head);

void show(Node *head){
//cout<<head->data<<' ';
while(head->next){
head=head->next;
cout<<head->data;
if(head->next)
cout<<' ';
}
cout<<endl;
}

销毁

1
2
3
4
5
6
7
8
9
10
11
12
13
void destroy(Node *head);

destroy(head);

void destroy(Node *head){
Node *p;
while(head->next){
p=head->next;
head->next=p->next;
delete p;
}
delete head;
}

删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int deletenode(Node *H,int i);

deletenode(head,i);

int deletenode(Node *H,int i){
if(i>=1 && i<=H->data){
Node *q=H;
for(int j=1;j<i;j++){
q=q->next;
}
Node *p=q->next;
q->next=p->next;
H->data--;
return 1;
}
else
return 0;
}

插入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int insert(Node *H,int i,int data);

insert(head,index,data);

int insert(Node *H,int i,int data){
if(i>=1 && i<=H->data+1){
Node *p=new Node;
Node *q=H;
for(int j=1;j<i;j++){
q=q->next;
}
p->data=data;
p->next=q->next;
q->next=p;
H->data++;
return 1;
} else
return 0;
}

指针

堆内存分配

一维

1
2
int *p=new int[10];
delete []p;

二维

1
2
3
4
5
6
7
8
int **p=new int*[m];
for(int i=0;i<m;i++){
p[i]=new int[n];
}
for(i=0;i<m;i++){
delete []p[i];
}
delete []a;

指针作函数参数

1
2
3
4
5
6
void swap2( int *px, int *py ){  
int t;
t = *px;
*px = *py;
*py = t;
}

字符串赋值

1
2
3
4
5
6
7
8
9
10
11
12
char buffer[10]=“hello”;//初始化,ok

char buffer[10];
buffer=“hello”; //数组名赋值,error

const char* pc;
pc="hello"; //字符指针赋值,ok
const char *cities[5]={"Beijing","Shenzhen","Hangzhou"};

char* pc;
pc="hello"; //error
char *cities[5]={"Beijing","Shenzhen","Hangzhou"};

指针函数

1
2
3
4
5
int  *add(int *x)
{
*x=*x+5;
return x;
}

const 指针

常量指针(指向常量的指针)

1
2
3
4
const int a=89,b=60;
const int *p=&a;
p=&b; //ok
*p=100; //error

指针常量

1
2
3
4
int a =89,b=60;    
int *const p = &a;
p=&b; //error
*p=100; //ok

常量指针常量 (指向常量的指针常量)

1
2
3
4
const int a =89,b;    
const int *const p = &a;
p=&b; //error
*p=100; //error

函数指针

1
2
3
4
5
6
7
8
9
10
void sort(int* a,int n);
int main(){
int a[10]={9,34,2,1,-5,4,23,67,-123,0};
void (*pfun)(int *a,int n); //声明函数指针
pfun=sort; //给函数指针赋值
pfun(a,10); //使用函数指针调用函数
}
void sort(int* a,int n){
...
}

常用库函数

最大最小值

1
2
3
#include<climits>
int min=INT_MAx;
int max=INT_MIN;

排序

1
2
3
4
#include <algorithm>
int a[10]={45,12,34,77,90,11,2,4,5,55};
sort(a,a+10);
sort(a,a+10,greater<>());

排序算法

选择排序

选择排序

1
2
3
4
5
6
7
8
9
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(p[j]>p[i]){
int t=p[i];
p[i]=p[j];
p[j]=t;
}
}
}

冒泡排序

冒泡排序

1
2
3
4
5
6
7
8
9
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1-i;j++){
if(p[j+1]>p[j]){
int t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}

更多排序

点击查看

  • © 2019-2020 Bingoyyj
  • Powered by Hexo Theme Ayer
  • PV: UV:

什么?这次一定?

支付宝
微信