Posts

《Learning Python》 笔记 第 1 章 问答环节

《Learning Python》 笔记 第 1 章 问答环节 Python 是一门脚本语言吗 Python 是通用型编程语言,时常扮演脚本语言的角色。 Python 的缺点 比起完全编译并比较底层的语言,执行速度不够快。 使用 Python 可以做什么 系统编程、GUI、

[Vim] usr_07

usr_07 编辑多个文件 07.1 编辑另一个文件 :edit <FILENAME>需要先保存当前文件的修改,或者使用 :edit! <FILENAME>放弃当前文件修改并打开另一个文件。 想编辑其他文件又不保存当前文件则可

[Vim] usr_06

usr_06 使用语法高亮 06.1 功能激活 :syntax enable只在支持色彩的终端中生效,在 vimrc 中加入 if &t_Co > 1 syntax enableendif只在 Gui 版本生效则在 gvimrc 加入 syntax enable06.2 颜色显示不出来或者显示出错误的颜色怎么办? 终端不支持彩色,这时 vim 会

[Vim] usr_05

usr_05 选项设置 05.1 vimrc 文件 可以使用如下命令打开 Vim 配置文件 :edit $MYVIMRC可以在开头放上 source $VIMRUNTIME/defaults.vim来导入默认配置。vimrc 文件可以包含任何冒号命令。 05.2 vimrc 示例解释 if has("vms") set

[Vim] usr_04

usr_04 作小改动 04.1 操作符与动作 Vim 只删除从当前位置到”动作“把光标移动到的位置的前一个位置。是否包括光标所在的字符取决于你使用的移动命令。包括当前字符在参考手册中称为 inclusive、否则成为 exclusi

[Vim] usr_03

usr_03 移动 03.1 词移动 移动到下一个词开头位置 w移动到上一个词开头 b移动到下一个 单词末尾 e移动到前一个 单词末尾 ge一个单词以非单词字符(. - ( 等)结尾,要改变那些是单词字符详见 iskeyword 复位 iskeyword :set iskeyword$如果

[Vim] usr_02

usr_02 Vim 初步 02.1 第一次运行 Vim >gvim file.txt >vim file.txt 02.2 插入文本 普通模式 -> 插入模式 Insert。 i插入模式 -> 普通模式 <ESC>显示当前模式 :set showmode02.3 光标移动 kh l j02.4 删除字符 删除光标处的字符 x删除整行 dd删除两行(与下行)

[Vim] usr_01

usr_01 检查是否是 vi 兼容模式 :set compatible?查找配置文件 :scriptnames运行 vim tutor >vimtutor vimtutor 笔记 移动 ^ k< h l > j v不保存退出 :q!<ENTER>保存退出 :wq<ENTER> 普通模式 删除光标位置的字符 x普通

《C++ Primer》 拾遗 第 16 章 模板与泛型编程

第 16 章 模板与泛型编程 本章内容随便记记,应该后续会跟进专门的书籍仔细学习。 16.1 定义模板 16.1.1 函数模板 函数模板 function template 模板参数 template parameter 模板参数列表 template parameter list 模板定义中,模板参数列表不能为空? 使用模板时,我们隐式或显示的指定

《C++ Primer》 拾遗 第 14 章 重载运算与类型转换

第 14 章 重载运算与类型转换 14.1 基本概念 重载的运算符是具有特殊名字的函数。 重载运算符的参数数量与该运算符作用的运算对象数量一样多。除了重载的函数调用运算符 operator() 之外其他重载运算符不能含有默认实参。 一个重载运算符

[模板][数据结构] 下标池 IdPool

下标池 IdPool template<typename T> struct IdPool { map<T, int> idmap; vector<T> items; void clear() { idmap.clear(); items.clear(); } int getid(const T &t) { auto it = idmap.find(t); if (it != idmap.end()) return it->second; int ans = items.size(); items.push_back(t); idmap[t] = ans; return ans; } T& operator[](int i) { return items[i]; } int size() { return items.size(); } }; IdPool<int> idp;

《C++ Primer》 拾遗 第 13 章 拷贝控制

第 13 章 拷贝控制 拷贝控制 copy control 操作包括: 拷贝构造函数 copy constructor 拷贝赋值运算符 copy-assignment operator 移动构造函数 move constructor 移动赋值运算符 move-assignment operator 析构函数 destructor 13.1 拷贝、赋值与销毁 合成拷贝构造函数 synthesized copy constructor #include <iostream>#include <string>using namespace std; class A { public: string name; A() : name("") { cout << "default ctor" << endl; } A(string

《C++ Primer》 拾遗 第 12 章 动态内存

第 12 章 动态内存 静态内存用来存储 局部 static 对象,类 static 成员,定义在任何函数之外的变量。 栈内存用来存储 定义在函数内的非 static 对象。 除了这两部分,程序还拥有一个内存池。这部分内存被称为自由空间 free store 或 堆 heap。程序用

《C++ Primer》 拾遗 第 11 章 关联容器

第 11 章 关联容器 关联容器 associative-container map set multimap multiset unordered_map unordered_set unordered_multimap unordered_multiset 11.1 使用关联容器 map 通常称为关联数组 associative array。 11.2 关联容器概述 有序容器的关键字类型 需要定义 <,且该运算需要满足严格弱序 strict weak ordering。 11.2.3 pair 类型 pair 定义在

[模板][计算几何] 平面最近点对

Title typedef long long LL; typedef vector<int> VI; typedef vector<VI> VVI; const LL INF=0x3f3f3f3f3f3f3f3f; inline LL sqr(LL x){ return x*x; } inline LL dis(const VI &a,const VI &b) { return sqr(a[0]-b[0])+sqr(a[1]-b[1]); } bool cmp(const VI &a, const VI &b) { return a[1]<b[1]; } VVI tmp; LL help(VVI &ps,int l,int r) { int n=r-l+1; if(n<=3) { LL ans=INF; for(int i=l;i<=r;i++) { for(int j=i+1;j<=r;j++) ans=min(ans,dis(ps[i],ps[j])); } sort(ps.begin()+l, ps.begin()+r+1, cmp); return ans; } int m=(l+r)>>1; int mp=ps[m][0]; LL ans=min(help(ps,l,m),help(ps,m+1,r)); int i=l,j=m+1,p=l; while(i<=m || j<=r) { if(i>m || j<=r&&cmp(ps[j],ps[i])) { tmp[p++]=ps[j++]; } else { tmp[p++]=ps[i++]; } } copy(tmp.begin()+l, tmp.begin()+r+1,ps.begin()+l); p=0; for(int i=l;i<=r;i++) { if(sqr(ps[i][0]-mp)

《C++ Primer》 拾遗 第 10 章 泛型算法

第 10 章 泛型算法 泛型算法 generic algorithm 10.1 概述 大多数算法定义在头文件 algorithm 中。另外在 numeric 种定义了一组数值泛型算法。 一般来说这些算法并不直接操作容器,二十遍历由两个迭代器指定的一个元素范围来进行操作。 10.2 初识泛型算法 10.2.1 只读算

《C++ Primer》 拾遗 第 9 章 顺序容器

第 9 章 顺序容器 sequential container 9.1 顺序容器概述 vector deque list forward_list array string 9.2 容器库概览 类型别名 意义 iterator 迭代器类型 const_iterator 不能修改元素的迭代器类型 size_type 容器类型最大可能的大小 difference_type 两个迭代器间的距离 value_type 元素类型 reference 元素的左值类型与 value_type& 相同 const_reference 元素的 const 左值类

《C++ Primer》 拾遗 第 8 章 IO 库

第 8 章 IO 库 8.1 IO 类 头文件 类型 作用 iostream istream, wistream 从流读 ostream, wostream 向流写 iostream,wiostream 读写流 fstream ifstream, wifstream 从文件读 ofstream, wofstream 向文件写 fstream, wfstream 读写文件 sstream istringstream, wistringstream 从 string 读 ostringstream, wostringstream 向 string 写 stringstream, wstringstream 读写 string ifstream 和 istringstream 继承自 istream ofstream 和 ostringstream 继承自 ostream IO 对象没有拷贝和赋值操作。 8.1.2 条件状态 IO 类定

《C++ Primer》 拾遗 第 7 章 类

第 7 章 类 类的基本思想是数据抽象 data abstraction 和封装 encapsulation。 数据抽象是一种依赖于接口 interface 和实现 implementation 分离的编程/设计技术。 7.1 定义抽象数据类型 引入 this this 是一个常量指针。 成员函数通过隐式参数 this 来访问调用它

《C++ Primer》 拾遗 第 6 章 函数

第 6 章 函数 6.1 函数基础 我们可以通过调用运算符 call operator 来执行函数。 形参 parameter 实参 argument 主调函数 calling function 被调函数 called function 空形参列表可以是空的括号,或是 void void f1() {} void f2(void) {} 6.1.1 局部对象 C++ 中名字有作用域,对象有声明周期 lifetime。 名