- 博客(223)
- 问答 (1)
- 收藏
- 关注
原创 矩阵快速幂: 网易2017实习生编程题 魔力手环
描述: 小易拥有一个拥有魔力的手环上面有n个数字(构成一个环),当这个魔力手环每次使用魔力的时候就会发生一种奇特的变化:每个数字会变成自己跟后面一个数字的和(最后一个数字的后面一个数字是第一个),一旦某个位置的数字大于等于100就马上对100取模(比如某个位置变为103,就会自动变为3).现在给出这个魔力手环的构成,请你计算出使用k次魔力之后魔力手环的状态。 输入描述: 输入数据包括两行:...
2018-02-11 14:27:40
536
原创 朴素贝叶斯
常用于文档分类叫做朴素的原因: 整个形式化过程只作最原始、最简单的假设,概率独立性优点: 在数据较少的情况下仍然有效,可以处理多类别的问题 缺点: 对输入数据的准备方式较为敏感 使用数据类型: 标称型数据 条件概率 从文本构建词向量def createVacabList(dataSet): vacabSet = set([]) for docum
2018-01-16 16:57:16
454
原创 决策树(ID3用于标称型数据)
优点: 计算复杂度不高,输出结果易于理解,对中间值不敏感,可以处理不相关特征数据。 缺点: 可能会产生过度匹配问题。 适用数据类型: 数值型和标称型 信息增益 划分数据集的最大原则:将无序的数据变得更加有序 在划分数据集之前之后信息发生的变化称为信息增益 获得最多信息增益的特征就是最好的划分数据集的选择 计算香农熵代码def calcShannonEnt(dataSet
2018-01-16 16:02:49
807
原创 KNN K近邻算法
只选择样本数据集中前K个最相似的数据,K通常是不大于20的整数,最后选择k个最相似数据中出现次数最多的类,作为新数据的分类。 优点: 精度高,对异常值不敏感,无数据输入假定 不用训练算法 缺点: 计算复杂度高,空间复杂度高 适用范围: 数值型和标称型 代码:from numpy import *import operatordef createDataSet():
2018-01-13 17:51:50
392
原创 Django :验证码
如果使用Django 自带的csrf_token其实是不安全的,因为它实际上就是在HTML中嵌入一个hidden input,我把它复制下来照样也可以跨站请求,所以我们就需要更加安全的机制,验证码。 代码效果: (图中蓝色高亮的部分就是csrf_token的实际代码) 以下为具体的实现步骤: 1,准备验证码图片 在views.py中添加如下代码:from django.http imp
2017-11-29 17:16:26
636
原创 setTimeout:pop a window
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale
2017-11-05 12:44:32
388
原创 responsive layout in css
In this demo,first there will be 4 gold block ,when you shrink the width of the window,it will be 2 gold blocks per line and the 1 gold block per line;<!doctype html><html lang="en"><head> <meta
2017-11-04 16:50:06
463
原创 picture_info demo of transition in css
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale
2017-11-04 11:48:23
358
转载 样式重置 css reset
原地址: 新浪的初始化:html,body,ul,li,ol,dl,dd,dt,p,h1,h2,h3,h4,h5,h6,form,fieldset,legend,img { margin: 0; padding: 0}fieldset,img { border: 0}img { display: block}address,caption,cite,co
2017-10-18 17:34:46
932
原创 news_list
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale
2017-10-10 22:17:53
785
原创 Making the text surround the picture
In this example,it uses the ‘float’ attribute to achieve it; The float element will on the top of the element that doesn’t float,the tow element will overlap<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
2017-10-07 18:13:11
378
原创 menu bar (html+css)
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale
2017-10-07 11:11:51
633
原创 simple traditional layout in html(use table)
code:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Hello!</title></head><body> <table width="800" height="800" border="0" cellspacing="0" cellpadding="0" align="ce
2017-10-06 11:50:44
438
原创 simple dynamic web server with self defined framework (python)
The framework import timefrom test1 import HTTPServerclass Applicatoin(object): def __init__(self,urls): self.urls = urls def __call__(self, evn, start_response): path = evn.get
2017-10-05 23:09:32
442
原创 正则表达式Reguler Expression (with python re)
在Python中需要通过正则表达式对字符串进行匹配的时候,可以使用一个模块,名字为re //‘match’ scan a string start from the very left,if it not match,it will break#coding=utf-8# 导入re模块import re# 使用match方法进行匹配操作 result = re.match(正则表达式,要匹
2017-10-05 14:00:11
510
原创 Web static server
from socket import *from multiprocessing import Processimport redef fun(client_socket): documentRoot = './Html' client_data = client_socket.recv(1024) client_data_lines = client_data.split
2017-10-03 15:40:35
503
转载 Different types Server in Python
multiprocess(The almost same as threading)from socket import *from multiprocessing import *from time import sleepdef dealWithClient(newsocket,cAddr): while True: recvData = newsocket.recv
2017-10-01 17:52:11
486
原创 TCP_client and server in py
The client:from socket import *clientscoket = socket(AF_INET,SOCK_STREAM)clientscoket.bind(("",4568))clientscoket.connect(("your IP",port))clientscoket.send(b"hahha")recvData = clientscoket.recv(10
2017-09-28 15:03:30
380
原创 udp_socket with thread to contect with each other
from threading import Threadfrom socket import *def sendinfo(): while True: sendinfo = input('<<') udpSocket.sendto(sendinfo.encode('utf-8'),adress)def recvinfo(): while True:
2017-09-27 17:57:23
495
原创 async in multiprocess_pool
from multiprocessing import Poolimport timeimport osdef test(): print('---the process in pool---pid = %d,ppid = %d---'%(os.getpid(),os.getppid())) for i in range(3): print('---%d -- '
2017-09-25 21:27:44
365
原创 multiprocessing_Manager().Queue()_Pool
This code is to realize copy multiple files in one file to the other file by Pool in multiprocessing ,to reduce the time.import timefrom multiprocessing import Pool,Managerimport osdef copyFileTask(
2017-09-22 22:39:39
3602
1
原创 Tkinter _event
#test for three event in Tkinter : command ,bind, protocolfrom Tkinter import *import tkMessageBoxroot = Tk()def callback(event): frame.focus_set() print "click at:",event.x,event.ydef Key(ev
2017-09-15 12:15:16
2335
转载 2017ACM/ICPC广西邀请赛 K- Query on A Tree trie树合并
转载自:http://www.cnblogs.com/zxhl/p/7459240.htmlProblem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen o
2017-09-06 15:09:16
493
转载 ***hdu6183
Do you like painting? Little D doesn’t like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to mai
2017-09-06 15:06:21
597
转载 zoj3800线段树+离线
You are given a sequence {A0, A1, …, AN-1} and an integer set called GS. Defined a function called G(L, R) on A, where G(L, R) = GCD(Ai) (L ≤ i < R) that is the greatest common divisor of all the integ
2017-09-03 08:27:44
435
原创 hdu3085双向bfs+曼哈顿距离判断
Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were trapped in a big maze separately. More terribly, there are two ghosts in the maze. They will kill the pe
2017-09-01 17:06:26
512
原创 hdu3533bfs+预处理
The students of the HEU are maneuvering for their military training. The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to
2017-09-01 14:33:37
355
原创 poj3728并查集+LCA
题目大意: 对于一棵树,树上的每点都有一个权值,对于一个询问u,v,求从u 点到v点的路径上进行买卖所能得到的最大值,并且,买在卖之前。 There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some
2017-08-30 16:30:46
332
原创 vim常用命令总结
三种模式:命令模式,末行模式,插入模式esc:将任何模式切换到命令模式从命令模式切换到插入模式: i:在当前光标之前插入字符 I:在行首插入字符 a:在当前光标之后插入字符 A:在行末插入字符 o:在下一行新建一行并且插入字符 O:在上一行新建一行并且插入字符命令模式下: dd:剪切当前行(剪切后不粘贴即为删除) 数字+dd:删除从当前航开始的几行yy:复制当前行 数字+yy:从当
2017-08-26 19:14:43
347
转载 康托展开
文字及图转自:http://www.cnblogs.com/1-2-3/archive/2011/04/25/generate-permutation-part2.html代码转自:http://blog.youkuaiyun.com/synapse7/article/details/16901489康托展开的公式是 X=an*(n-1)!+an-1*(n-2)!+…+ai*(i-1)!+…+a2*1!+a1*
2017-08-24 11:01:10
307
原创 hdu 4638 Group
There are n men ,every man has an ID(1..n).their ID is unique. Whose ID is i and i-1 are friends, Whose ID is i and i+1 are friends. These n men stand in line. Now we select an interval of men to make
2017-08-23 20:02:43
351
转载 HYSBZ2038 小Z的袜子(莫队算法)
原地址:http://www.cnblogs.com/chanme/p/3681999.html 今天学了一下传说中的解决离线询问不修改的一种算法。题目的意思非常简单,就是询问在一个[L,R]区间里的取两个物品,然后这两个物品颜色相同的概率。其实就是对于每种颜色i,这个区间里对应的个数cnt[i],那么答案就应该是 sigma (cnt[i]cnt[i-1]) / (R-L+1)(R-L). 问
2017-08-22 10:00:32
370
转载 hdu 6155 - Subsequence Count 线段树+dp+矩阵
参考的原博客:http://www.cnblogs.com/iRedBean/p/7398272.html #include <bits/stdc++.h>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int n,q;const int maxn=1e5+9;const long long mod
2017-08-21 11:40:21
460
原创 hdu1166 敌兵布阵
大意: 在给定区间修改某一点的值,然后查询某一个区间的和;思路: 分块; 如果包含整区间的话,那就直接加上整个区间的值;否则暴力累加每一个点的值;#include <bits/stdc++.h>using namespace std;const int maxn=5e4+9;int a[maxn];long long sum[maxn];int main(){ int t;
2017-08-20 20:28:14
395
原创 hdu4348To the moon
Background To The Moon is a independent game released in November 2011, it is a role-playing adventure game powered by RPG Maker. The premise of To The Moon is based around a technology that allows
2017-08-20 11:12:55
473
原创 hdu6154CaoHaha's staff
Problem Description “You shall not pass!” After shouted out that,the Force Staff appered in CaoHaha’s hand. As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,i
2017-08-19 18:54:31
1325
转载 hdu6133
Though being cruel and merciless in the battlefields, the total obedience to the command hierarchy makes message delivering between Stormtroopers quite inefficient, which finally caused the escape of L
2017-08-18 16:48:29
408
转载 use api in pygal
import requestsimport pygalfrom pygal.style import LightColorizedStyle as LCS,LightenStyle as LSurl='https://api.github.com/search/repositories?q=language:python&sort=stars'r = requests.get(url)pri
2017-08-17 23:46:00
548
原创 BZOJ2243
给定一棵有n个节点的无根树和m个操作,操作有2类: 1、将节点a到节点b路径上所有点都染成颜色c; 2、询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“ 112221 ” 由3段组成:“ 11 ” 、“ 222 ” 和“ 1 ” 。 请你写一个程序依次完成这m个操作。 Input 第一行包含2个整数n和m,分别表示节点数和操作数; 第二行包含n个正整数表示n个节点
2017-08-16 20:35:47
556
原创 process json in pygal
import jsonfrom random_walk import get_country_codefrom pygal.maps.world import Worldfrom pygal.style import RotateStylefrom pygal.style import LightColorizedStyle#from pygal.style import RotateSt
2017-08-15 23:20:05
552
空空如也
python使用pygal报错:
2017-08-05
TA创建的收藏夹 TA关注的收藏夹
TA关注的人