自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 收藏
  • 关注

原创 [LeetCode]Keyboard Row - Python

输入一个字符串list,如[“Hello”, “Alaska”, “Dad”, “Peace”],对于list中的每一个字符串,如果这个字符串中的字母的集合小于等于键盘上的任意一行字母的集合,就输出这个字符串。在此例子中,输出[“Alaska”, “Dad”]。class Solution(object):def findWords(self, words): """ :type

2017-02-20 18:59:40 824

原创 [LeetCode]Number Complement - Python

给定一个正整数,输出它的补数,补数就是翻转原数二进制形式的每一位,如5(101)的补数为2(010)。class Solution(object):def findComplement(self, num): """ :type num: int :rtype: int """ i = 1 while i <= num: num ^=

2017-02-20 18:51:37 1248

原创 [LeetCode]Hamming Distance - python 1 line

Hamming Distance(汉明距离)在此问题中,指两个整数转为二进制后,其对应位置上相异字符的个数。如x=1=(0 0 0 1)b, y=4=(0 1 0 0)b,则相异的位置氛围是第二和第四位,即汉明距离为2。 Python一行代码实现如下:class Solution(object):def hammingDistance(self, x, y): """ :type

2017-02-18 13:20:36 370

原创 主成分分析Matlab实现

%数据导入及处理clcclear allA=xlsread('coach.xlsx','B2:H16');%数据标准化处理a=size(A,1);b=size(A,2);for i=1:b SA(:,i)=(A(:,i)-mean(A(:,i)))/std(A(:,i));end%计算相关系数矩阵的特征值和特征向量CM=corrcoef(SA);%计算相关系数矩阵[V

2015-08-22 14:17:35 3615

原创 Matlab中数据的标准化处理

%function std_attrValues= vecStd(attrValues)%if iscolumn(attrValues)~=1% 如果不是指标数据列向量,则提示错误%warndlg('输入数据必需为列向量,数据标准化处理失败,返回空值!','失败!');%std_attrValues=[]; % 调用错误时返回空值%elsem=length(attrValues); %

2015-08-22 10:28:54 14575

原创 层次分析法(AHP) 将评判矩阵转化为权重矩阵代码实现 MATLAB

% AHP权重计算 Matlab程序% 数据读入clcclear allA=[1 2 6;1/2 1 4;1/6 1/4 1]; %评判矩阵%一致性检验和权向量计算[n,n]=size(A);[v,d]=eig(A);r=d(1,1);CI=(r-n)/(n-1);RI=[0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45 1.49 1.52 1.54

2015-08-21 13:40:41 6425

原创 元胞自动机 Matlab实现表面张力

clfclear all%build the GUI%define the plot buttonplotbutton=uicontrol('style','pushbutton',... 'string','Run',... 'fontsize',12,... 'position',[100,400,50,20],... 'callback','run=1

2015-08-20 15:29:23 1690

原创 元胞自动机 生命游戏 Matlab实现 GUI

clfclear all%build the GUI%define the plot buttonplotbutton=uicontrol('style','pushbutton',... 'string','Run',... 'fontsize',12,... 'position',[100,400,50,20],... 'callback','run=1

2015-08-20 15:02:11 8486

原创 逆波兰表达式

#includeusing namespace std;double notation(){ char str[10]; cin>>str; switch(str[0]){ case'+': return notation() + notation(); case'-': return notation() - notation(); case'*': return

2015-08-05 15:38:50 278

原创 POJ 2533 Longest Ordered Subsequence

#includeusing namespace std;int main(){ int n; cin>>n; int a[1004]={0}; int b[1004]={0}; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++){ b[i

2015-08-05 14:50:00 260

原创 POJ 2247 Humble Numbers

#include#include#define maxnum 2000000000using namespace std;int a[5850]={0};int main(){ long long n2=1,n3=1,n5=1,n7=1; int n,count=0; while(n2<=maxnum){ n3=1;

2015-08-05 14:42:16 272

原创 POJ 1163 The Triangle

#include#includeusing namespace std;int main(){ const int size=101; int triangle[size][size]; int* maxSum; int n;//行数 int i,j; cin>>n; for(i=1;i<=n;i++) for(j=1;j<=i;j++) cin>>triang

2015-08-05 14:40:36 190

原创 POJ1664 放苹果儿

#includeusing namespace std;int f(int m,int n){ if(m<=1 || n<=1) return 1; if(n>m) return f(m,m); else return f(m,n-1)+f(m-n,n);}int main(){ int t; cin>>t; int m,n; while(t){ cin

2015-08-05 14:27:52 267

原创 Cantor 康拓展开

const int PermSize = 10;long long factory[PermSize]={0,1,2,6,24,120,720,5040,40320,362880};long long Cantor(string buf){ int i, j, counted; long long result = 0; for(i = 0; i < PermSiz

2015-08-03 21:22:20 466

原创 三向切分的快速排序

对于存在大量重复元素的数组,这种方法比标准的快速排序的效率高得多。

2015-07-28 11:28:27 604

原创 堆排序

#includeusing namespace std;void heap(int *a,int i,int size){ int left=2*i; int right=2*i+1; int tag=i; if(i<=size/2){ if(lefta[tag]) tag=left; if(righta

2015-07-19 17:09:23 252

原创 归并排序

/*一种基于比较的排序算法,基本思想为分冶。时间复杂度为θ(nlogn)。性质:稳定,即相等的项彼此的相对位置不会发生改变。*/void mergeSort(int* A,int x,int y,int* T){ if(y-x>1) { int m=x+(y-x)/2; //划分 int p=x,q=m,i=x; mergeSort(A,x,m,T);//递归求解

2015-07-17 18:53:45 244

原创 希尔排序

/*交换不相邻的元素以对数组的局部进行排序,并最终用插入排序将局部有序的数组排序。思想是使数组中任意间隔为h的元素都是有序的。实现希尔排序的一种方法是对于每个h,用插入排序将h个子数组独立地排序。但因为子数组是相互独立的,一个更简单的方法是在h-子数组中将每个元素交换到比它大的元素之前去(将比它大的元素向右移动一格)。希尔排序更高效是因为权衡了子数组的规模和有序性。对于中等大小的数组,它

2015-07-17 17:53:46 346

原创 带哨兵与不带哨兵的插入排序

/*插入排序所需的时间取决于输入中元素的初始顺序 */#includeusing namespace std;const int arraySize=10;int main(){ int a[10]={1,6,2,4,3,5,8,7,9,0}; int temp; for(int i=0;i<arraySize;i++){ for(int j=i; j>0 && a[j]<a

2015-07-17 17:19:44 1084

原创 选择排序

首先,找到数组中最小的那个元素,其次,讲它和数组的第一个元素交换位置(如果第一个元素就是最小元素那么它就和自己交换)。再次,在剩下的元素中找到最小的元素,将它与数组的第二个元素交换位置。如此往复,直到将整个数组排序。对于长度为N的数组,选择排序需要大约N^2/2次比较和N次交换。特点:运行时间和输入无关。数据移动是最少的。#includeusing namespace std;con

2015-07-17 17:03:30 240

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除