- 博客(11)
- 资源 (13)
- 收藏
- 关注
原创 现在有一个整数数组,已知一个数出现的次数超过了一半,请用O(n)的复杂度的算法找出这个数
<br /> <br />现在有一个整数数组,已知一个数出现的次数超过了一半,请用O(n)的复杂度的算法找出这个数。<br />方法1:Hash链表<br />方法2:使用两个变量A和B,其中A存储某个数组中的数,B用来计数。开始时将B初始化为0。 <br />遍历数组,<br />如果B=0,则令A等于当前数,令B等于1;<br />如果当前数与A相同,则B=B+1;<br />如果当前数与A不同,则令B=B-1。<br />遍历结束时,A中的数就是要找的数。 <br />这个算法的时间复杂度是O(n),
2011-03-29 20:50:00 3677 2
原创 回溯法-子集和数问题
<br />/*回溯法-子集和数问题 */ #include <stdio.h>int M,n;int w[100];int x[100];void SumOfSub(int s, int k, int r){ //s=w[1]*x[1]+...+w[k-1]*x[k-1] //r=w[k]+...w[n] //w[i]需要按非降次序排列 int i; x[k]=1; for(i=1; i<=k; i++)
2011-03-24 23:13:00 10824 4
原创 回溯法-求n皇后问题
/*回溯法----n皇后问题 */#include #include int x[10000];/*判断x[k]是否符合要求*/int Place(int k){ int i; i=1; while(i0) { x[k]++; //移动到下一列 while(x[k]
2011-03-24 21:45:00 1060
原创 0-1背包问题——使用动态规划方法解决
/*背包问题——使用动态规划方法解决 */ #include void DKNAP_Pack(float p[], float w[], float M, int n, int x[]){ float P[1000],W[1000],pp,ww; int F[100]; int i,j,k,l,h,next,u; l = h = 1; F[0] = 1; P[1] = W[1] = 0; F[1] = n
2011-03-21 10:09:00 1445
原创 每对结点之间的最短路径——Floyd算法
<br />基本思想:动态规划<br /> <br />A[i][j] = min{A[i][j], A[i][k]+A[k][j]}<br /> <br />/*求每对结点之间的最短路径——Floyd算法 */#include <stdio.h>typedef struct Graph{ int cost[10][10]; int A[10][10];}MGraph;void ShortestPath_Floyd(MGraph &T, int n){
2011-03-20 18:43:00 1923
原创 快速排序-应用
<br /> <br />问题:给一系列a1、a2.。。。an,要求找出其中两个数ai和aj,<br />使ai+aj=X,算法复杂度为O(nlogn)。<br />思路是:先快速排序<br />然后用i j 分别指向头,尾<br />比较ai+aj?X<br />如果ai+aj>X j-- <br />如果ai+aj<X i++<br /> <br /> <br />/*问题:给一系列a1、a2.。。。an,要求找出其中两个数ai和aj,使ai+aj=X,算法复杂度为O(nlogn)。思路是:
2011-03-19 21:25:00 869
原创 贪心方法-带有限期和收益的单位时间的作业排序贪心算法和背包问题
参考《计算机算法基础》华中科技大学版1. 带有限期和收益的单位时间的作业排序贪心算法/*带有限期和收益的单位时间的作业排序贪心算法 */#include /*算法1,复杂度O(n*n)*/void JS(int d[], int J[], int n, int &k){ /*终止时,d[J[i]] d[i] && d[J[r]] != r) r--; if(d[J[r]] r) { fo
2011-03-19 21:21:00 7859 1
原创 C语言文件操作-带命令行参数
<br />采用命令行方式复制任意多个文件内容到一个文件中,如下所示:<br />命令行形式:mycopy 1.txt 2.txt 3.txt 4.txt ...<br />功能:复制2.txt 3.txt 4.txt …的内容到1.txt中<br /> <br />#include <stdio.h>#include <string.h>#include <stdlib.h>#define BUFSIZE 1000int main(int argc, char *argv[]){
2011-03-11 15:11:00 3280
原创 图像处理-Hough线变换和园变换
1. Hough线变换//Hough线变换#include "cv.h"#include "highgui.h"int main() { // TODO: Add your command handler code here IplImage* pImage= NULL;// 声明IplImage 变量 IplImage* pImg8u= NULL;// 声明IplImage 变量,用于图像格式转换 IplImage* pImgCanny= NULL;// 声明IplIm
2011-03-06 00:00:00 3205 3
原创 图像处理-Canny算子、Sobel算子边缘检测
1. Canny算子边缘检测//Canny-边缘检测#include "cv.h"#include "highgui.h"int main() { // TODO: Add your command handler code here IplImage* pImage= NULL;// 声明IplImage 变量 IplImage* pImgCanny= NULL;// 声明IplImage 变量,用于灰度图像Canny变换 IplImage* pImg8u= NULL;//
2011-03-05 23:58:00 5262
原创 OpenCV使用简单举例-图像显示
OpenCV示例:读入一幅图像,显示并存入D盘根目录:#include "cv.h"#include "highgui.h"int main(){ //定义IplImage指针变量src IplImage *src; //将src指向当前工程目录下的图形lena.jpg src = cvLoadImage("lena.jpg", -1); //定义一个窗口名为lena.jpg的显示窗口 cvNamedWindow("lena.jpg", 0); //在窗口lena.
2011-03-04 17:24:00 1089
Virtual Machines Versatile Platforms for Systems and Processes
2017-10-13
修改代码的艺术 中文版
2017-09-23
Netty5.0 架构剖析和源码解读
2017-09-18
matlab 7.0 在数字信号处理中的应用
2010-04-03
Linux Command Directory
2009-10-28
Win32help.exe
2009-10-16
新编windows32 api参考大全
2009-10-16
Standard C Library c++ STL
2009-09-26
GNU.C++.for.Linux
2009-09-02
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人