08 2018 档案
摘要:# for i in range(1, 10): # for j in range(1, i + 1): # print('%s * %s = %s ' % (i, j, i * j), end='') # print() [print('%s * %s = %s\n' % (i, j, i * j)) if i == j else print('%s * %...
阅读全文
摘要:用Python一键搭建Http服务器的方法 Python3请看 python -m http.server 8000 & Python2请看 python -m SimpleHTTPServer 8000 & 总之就是一条Python命令就能在当前目录起一个Http服务器,然后就可以下载文件了。嗯,
阅读全文
摘要:数据结构 栈,队列,链表 •哈希表,哈希数组 •堆,优先队列 双端队列 可并堆 左偏堆 •二叉查找树 Treap 伸展树 •并查集 集合计数问题 二分图的识别 •平衡二叉树 •二叉排序树 •线段树 一维线段树 二维线段树 •树状数组 一维树状数组 N维树状数组 •字典树 •后缀数组,后缀树 •块状链
阅读全文
摘要:归并排序也是一种常用的排序算法, 其时间复杂度为O(n*logn), 它的基础是分治的思想。 其基本思路就是把数组分成两组A,B, 如果这两组内的数据都是有序的, 那么就可以很方便的对这两组数据进行合并排序。 但是如何让这两组数据有序呢? 归并法的思想就是把A,B两组各自再分成两组, 依次类推, 当分出来的小组数据只有一个的时候, 即可以认为小组数据已经达到了有序。 然和合并相邻的两个小组就OK...
阅读全文
摘要:#堆排序升序: #include #include #include using namespace std; #define parent(i) (i)/2 #define left(i) 2*(i) #define right(i) 2*(i)+1 int size; void heapify(int a[], int i) { int l = left(i), r = ...
阅读全文
摘要:#include int a[101],n;//定义全局变量,这两个变量需要在子函数中使用 void quicksort(int left,int right) { int i,j,t,temp; if(left>right) return; temp=a[left]; //temp中存的就是基准数 i=left; j=righ...
阅读全文
摘要:#include #include "cstring" #include "string" using namespace std; const int L=10000; int main(){ int i,n,a[L],num[L+1],Size; int T; cin>>T; while (T--) { cin>>n; ...
阅读全文
摘要:Problem Description 学会了单向链表,我们又多了一种解决问题的能力,单链表利用一个指针就能在内存中找到下一个位置,这是一个不会轻易断裂的链。但单链表有一个弱点——不能回指。比如在链表中有两个节点A,B,他们的关系是B是A的后继,A指向了B,便能轻易经A找到B,但从B却不能找到A。一个简单的想法便能轻易解决这个问题——建立双向链表。在双向链表中,A有一个指针指向了节点B,同时,B...
阅读全文
摘要:Problem Description n个人想玩残酷的死亡游戏,游戏规则如下: n个人进行编号,分别从1到n,排成一个圈,顺时针从1开始数到m,数到m的人被杀,剩下的人继续游戏,活到最后的一个人是胜利者。 请输出最后一个人的编号。 Input 输入n和m值。 Output 输出胜利者的编号。 Example Input 5 3 Example Output 4 Hint 第一轮:3...
阅读全文
摘要:Problem Description 按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除(值相同的元素只保留最后输入的一个)。 Input 第一行输入元素个数n; 第二行输入n个整数。 Output 第一行输出初始链表元素个数; 第二行输出按照逆位序所建立的初始链表; 第三行输出删除重复元素后的单链表元素个数; 第四行输出删除重复元素后的单链表。 Example I...
阅读全文
摘要:Problem Description 输入N个整数顺序建立一个单链表,将该单链表拆分成两个子链表,第一个子链表存放了所有的偶数,第二个子链表存放了所有的奇数。两个子链表中数据的相对次序与原链表一致。 Input 第一行输入整数N;; 第二行依次输入N个整数。 Output 第一行分别输出偶数链表与奇数链表的元素个数; 第二行依次输出偶数子链表的所有数据; 第三行依次输出奇数子链表的所有数据。...
阅读全文
摘要:任意一个大于1的正整数都能表示成若干个质数的乘积,且表示的方法是唯一的。换句话说,一个数能被唯一地分解成质因数的乘积。因此这个定理又叫做唯一分解定理。
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define maxn 205 int d[6][3]={{1,0,0},{-1,0,0}...
阅读全文
摘要:#include #include #include #define N 10000 int main() { char str[N]; int len;int i; int mod; int ans=0; int Case; scanf("%d",&Case); while(Case--){ scanf("%s",str); ...
阅读全文
摘要:#include #include #include #include #include using namespace std; typedef long long ll; ll ksm(ll a, ll b, ll c) { ll ans=1; a=a%c; while(b>0) { if(b%2==1) ans=(an...
阅读全文
摘要:#include using namespace std; #include #include void sqrt(char *str) { double i,r,n; int j,l,size,num,x[1005]; size=strlen(str); if (size==1&&str[0]=='0') { cout=size)...
阅读全文
摘要:大数除法,应该算是四则运算里面最难的一种了。不同于一般的模拟,除法操作步数模仿手工除法,而是利用减法操作实现的。 其基本思想是反复做除法,看从被除数里面最多能减去多少个除数,商就是多少。 逐个减显然太慢,要判断一次最多能减少多少个整的10的n次方。 以7546除23为例。 先减去23的100倍,就是2300,可以减3次,余下646。 此时商就是300; 然后646减去23的10倍,就是230...
阅读全文
摘要:#include #include #include void reverseOrder(char* str, int p, int q) { char temp; while(p < q) { temp = str[p]; str[p] = str[q]; str[q] = temp; p ++; ...
阅读全文
摘要:#include #include #include // 功能:实现两个大数减法运算 // 参数:source1--被减数 // source2--减数 // result --计算结果 // 返回值:计算结果为正数,返回'+',否则返回'-' char Minus(char *source1, char *source2, char *result) { ...
阅读全文
摘要:#include #include #include #include #include using namespace std; string bigmun(string a,string b){ string c; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); char ans[2...
阅读全文
摘要:架构: C/S架构:充分发挥PC机的性能 B/S架构:统一了应用接口,隶属于C/S架构 物理地址:mac,全球唯一,类似于一个身份证 ip地址:四位点分十进制 8位点分二进制 (要求:二进制,十六进制,十进制) arp协议:通过目标ip地址,获取目标mac地址 OSI五层模型: 应用层 http协议
阅读全文
摘要:#logging模块 #功能: #1.日志格式的规范 #2.操作的简化 #3.日志的分级管理 #logging模块不能干什么 #1.自动生成要打印的内容 #2.需要程序员自己在开发的时候定义好: ####1)在哪些地方需要打印 ####2)打印内容是什么 ####3)内容级别是什么 #logging模块的使用 #1.普通配置型:简单的课定制化查 #2.对象配置型:复杂的可定制化强 im...
阅读全文
摘要:# configparser模块 #用于生成和修改常见的配置文档 # 该模块适用于配置文件的格式与windows ini文件类似, #可以包含一个或多个节(section),每个节可以有多个参数(键=值) #****创建文件**** # 来看一个好多软件的常见文档格式如下: [DEFAULT] ServerAliveInterval = 45 Compression = yes Co...
阅读全文
摘要:#序列化模块 #what #什么叫序列化--将原本的字典、列表等内容转换成一个字符串的过程叫做序列化。 #why #序列化的目的 ##1.以某种存储形式使自定义对象持久化 ##2.将对象从一个地方传递到另一个地方 ##3.使程序更具有维护性 #str-------------反序列化-------->>>数据结构 #数据结构 #注意:要用json转换完的字符串类型的字典中的字符串是由""表示的...
阅读全文
摘要:#hashlib模块 # Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等。 #1.什么是摘要算法呢?摘要算法又称哈希算法、散列算法。它通过一个函数, #把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示)。 #2.摘要算法就是通过摘要函数f()对任意长度的数据data计算出固定长度的摘要digest, #目的是为了发现原始数据是否被人篡改过。 ...
阅读全文
摘要:#include #include #include using namespace std; #define INF 10000 const int maxn = 300; int r[maxn][maxn]; int main() { int n, m; while (cin>>n>>m) { memset (r, INF, sizeof(r)...
阅读全文
摘要:#include #include #include #define MAXLEN 1005 #define inf 1> b >> e >> v; map[b][e] = map[e][b] = v; } } bool SPFA(int x, int n) { queue Q; memset(vis,0,sizeof(vis)); mem...
阅读全文
摘要:#include "iostream" #include "cstdio" #include "queue" #include #include #include "algorithm" using namespace std; #define Maxn 1005 #define inf 1 Q; memset(vis, 0, sizeof(vis)); memset(inq...
阅读全文
摘要:#include using namespace std; const int Max=99999999; int map[105][105]; int d[105]; int middist; bool s[105]; void dijkstra(int n,int m) { for(int i=1;i>N>>M&&N!=0&&M!=0) { for(int ...
阅读全文
摘要:#include #include #include #include #include #define N 110 #define INF 0x7ffffff using namespace std; int n,val[N],mp[N][N],d[N],v[N],num[N],r[N][N]; void floyd() { for(int k=1;k q; q.push(s...
阅读全文
摘要:1、os.path.getsize可以获取文件大小 import os file_name = 'XXXXXX'print(os.path.getsize(file_name)) 2、获取文件夹大小,即遍历文件夹,将所有文件大小加和。遍历文件夹使用os.walk函数 os.walk()可以得到一个三
阅读全文
摘要:datetime模块 datetime模块重新封装了time模块,提供更多接口,提供的类有:date,time,datetime,timedelta,tzinfo。 1、date类 datetime.date(year, month, day) 静态方法和字段 date.max、date.min:date对象所能表示的最大、最小日期; date.resolution:date对象表示日...
阅读全文
摘要:#时间模块 import time #常用方法 #time.sleep(secs)#(线程)推迟指定的时间运行。单位为秒 #print(time.time())#获取当前时间戳 #表示时间的三种方式 #在python中,通常有三种方式来表示时间:时间戳,元组(结构化时间),格式化的时间字符串: #1.时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00...
阅读全文
摘要:# sys模块是与python解释器交互的一个接口 import sys print(sys.argv) # 命令行参数list,第一个元素是程序本身路径 # (第一个元素就是执行文件的时候,写在python命令后的第一个值,之后的元素在执行 # python的启动的时候可以写多个值,这些值都会依次添加到列表中) # sys.exit() #t退出程序,正常退出时exit(0),错误退出s...
阅读全文
摘要:#os模块 用于提供系统级别的操作 #当前执行这个python文件的工作目录相关的工作路径 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径(在哪里执行就是那个路径) os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd os.curdi
阅读全文
摘要:Go 是一个开源的编程语言,它能让构造简单、可靠且高效的软件变得容易。 Go是从2007年末由Robert Griesemer, Rob Pike, Ken Thompson主持开发,后来还加入了Ian Lance Taylor, Russ Cox等人,并最终于2009年11月开源,在2012年早些时候发布了Go 1稳定版本。现在Go的开发已经是完全开放的,并且拥有一个活跃的社区。 Go...
阅读全文
摘要:#include "iostream" #include "algorithm" #include "cstdio" using namespace std; const int maxn=200; typedef struct { int a,b,v,c; }node; int ans; node graph[maxn*(maxn-1)/2]; int father[maxn]; in...
阅读全文
摘要:#include #include #include #include using namespace std; typedef struct { int a,b; double v; }node; typedef struct { int a,b; }P; const int maxn=109; double ans; int father[maxn]; nod...
阅读全文
摘要:HDU 1233(最小生成树 模板) #include #include #include using namespace std; typedef struct { int a,b; int v; }node; const int maxn=105; int ans; int father[maxn]; node graph[maxn*(maxn-1)/2]; int ...
阅读全文
摘要:http://poj.org/problem?id=3278 #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define maxn 1...
阅读全文
摘要:http://poj.org/problem?id=2386 #include #include using namespace std; const int MAX = 10000; char Map[MAX][MAX]; int N,M; int d[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; bool...
阅读全文
摘要:re模块 准备: flags有很多可选值: re.I(IGNORECASE)忽略大小写,括号内是完整的写法 re.M(MULTILINE)多行模式,改变^和$的行为 re.S(DOTALL)点可以匹配任意字符,包括换行符 re.L(LOCALE)做本地化识别的匹配,表示特殊字符集 \w, \W, \b, \B, \s, \S 依赖于当前环境,不推荐使用 re.U(UNICODE) 使用\w ...
阅读全文
摘要:在python中使用正则表达式 1.转义符 正则表达式中的转义: '\('表示匹配小括号 [()+*/?&.] 在字符组中一些特殊的字符会现出原形 所有的\s\d\w\S\D\W\n\t都表示他原本的意义 [-]只有写在字符组的首位的时候表示普通的减号 写在其它位置的时候表示范文[1-9]如果就是想匹配减号[1\-9] Python中的转义符 分析过程: '\n'#\是转义符 赋予这个n一个...
阅读全文
摘要:import requests from requests.exceptions import RequestException import re import json # 获取TOP100榜页面的URL def get_url_links(): base_url = 'http://maoyan.com/board/4?offset=' list_url = [] ...
阅读全文
摘要:本质:导入模块的本质就是把python文件解释一遍, 导入包的本质就是把包文件下面的init.py文件运行一遍。 1)同目录下模块的导入 #同级目录下模块的导入 import module_name #直接导入模块 import module1_name,module2_nam...
阅读全文
摘要:正则表达式 what:一种匹配字符串的规则 where:程序领域:1,登录注册的表单验证 2.爬虫 3.自动化开发 why:可以制定一个规则 1.来确认某一个字符串是否符合规则 2.从大段的字符串中找到符合规则的内容 how: 正则表达式的语法:1.元字符 2.量词 3.特殊用法和现象 1元字符 [...]----匹配字符组(集)中的字符 [^...]---匹配除了字符组中字符的所有字符...
阅读全文
摘要:https://github.com/Fover21/Mind-map
阅读全文
摘要:包是一种通过使用‘.模块名’来组织python模块名称空间的方式。 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的, 都要第一时间提高警觉:这是关于包才有的导入语法 2. 包是目录级的(文件夹级),文件夹是用来组成py文件(包的本质就是一个包含__init__.py文件的目录) 3. import导入文件时,产生名称空间中的名字...
阅读全文
摘要:# import 模块 # 导入这个模块之后 模块内的所有名字 就都可以通过模块来引用了 # 模块名.名字 # from 模块 import 名字 # 导入这个模块中的某个名字之后,这个名字就可以直接使用了 # 名字是变量 直接用 # 名字是函数 函数名()就是调用 # 名字是类名 类名()就是实例化 # 模块的循环引用 - 不能 # 把模块当成脚本运行 : # 你希望 某一段代码...
阅读全文
摘要:1.__new__ and __init__ 这两个方法都是在实例化的时候执行,__new__ 在 __init__ 之前执行,并且 如果实例化的时候封装属性,__new__也是必须要传的,而且__new__必须有返回 值,而且这个返回值就是对象的内存空间而且会传给__init__的self参数,而且 封装的属性也会传给__init__. class A: def __new__(c...
阅读全文
摘要:当类实例化的时候,通过__new__来创建对象空间, 如果实例化的时候带参数,那么__new__也是必须接受这个参数的,不接受会报错,而且这个__new__的返回值, 是传给__init__里面的self,参数传给对象封装属性。
阅读全文
摘要:#需求: # 一个类 # 对象的属性 : 姓名 性别 年龄 部门 # 员工管理系统 # 内部转岗 python开发 - go开发 # 姓名 性别 年龄 新的部门 # A men 83 python # A men 85 go # 1000个员工 # 如果几个员工对象的姓名和性别相同,这是一个人 # 请对这1000个员工做去重 #用到了set的内层如何实现,先hash,如果hash值一样的...
阅读全文
摘要:python 内置方法 __int__, __str__, __repr__,__eq__,__hash__他们是必须有返回值得! __init__ ,__hash__ 返回整数 __str__, __repr__ 返回字符串 __eq__ 返回布尔值
阅读全文
摘要:#------面向对象------# (1)什么时候用面向对象 ----答:1.代码量大,功能多。2.处理比较复杂角色之间的关系 #------创建一个对象------# 类名() 实例化 __new__()创造了一个对象的空间,还可以做一些简单的初始化。 #------创建一个类-------# class Leiming 语法级别,Python解释器读到就会创建一个类 type 是所...
阅读全文
摘要:算法的核心就在这一句上了:p[i] = min(p[2*id-i], p[id] + id - i); #include #include #include #include #include #include #include #include #include #include #include #include #include using name...
阅读全文
摘要:Problem Description 给定两个字符串string1和string2,判断string2是否为string1的子串。 Input 输入包含多组数据,每组测试数据包含两行,第一行代表string1(长度小于1000000),第二行代表string2(长度小于1000000),string1和string2中保证不出现空格。 Output 对于每组输入数据,若string2是...
阅读全文
摘要:它的优点是:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希树高。 它有3个基本性质: 根节点不包含字符,除根节点外每一个节点都只包含一个字符; 从根节点到某一节点,路径上经过的字符连接起来,为该节点对应的字符串; 每个节点的所有子节点包含的字符都不相同。 #include #include #include using namespace std; ...
阅读全文
摘要:1、应尽量避免在 where 子句中使用!=或操作符,否则将引擎放弃使用索引而进行全表扫描。 2、对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。 3、应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描。如: select id from t where num is null 可...
阅读全文
摘要:比如,斐波那契数列:1,1,2,3,5,8,13,21,34.... 用列表生成式写不出来,但是我们可以用函数把它打印出来: def fib(number): n, a, b = 0, 0, 1 while n 注意: ...
阅读全文
摘要:class Teacher: OPERATE_DIC = [ ('创建课程', 'create_course'), ('创造学生', 'create_student'), ('创建课程', 'create_course'), ('查看学生信息', 'check_student_info'), ] def _...
阅读全文