- 博客(28)
- 收藏
- 关注
原创 PSO粒子群优化算法
package pso;import java.util.Random;public class Particle { public double fitness; public double[] X; double[] v; double pbest;// 历史最优解 double ppos[];// 历史最优位置 public static double w; public static do...
2018-05-18 11:08:48
359
原创 蚁群算法
import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;/** * 蚁群优化算法,用来求解TSP问题 * * */public clas...
2018-05-18 11:06:41
392
原创 实数编码遗传算法求解函数最优值
目标函数:JAVA实现,定义了3个类:染色体类,GA类,测试类package test;import java.util.Random;public class Chrome { double[] genes; double fitness; double nfitness; int genelength; Random random = new Random(); /** * 初始化染色体 ...
2018-03-29 15:13:47
3571
原创 JAVA面向对象程序设计,董小园 清华大学出版社 课后上机实验题代码 第2章
2.1package test;public class Java2_1 { public static void main(String[] args) { Box myBox=new Box(); double myVol,myArea; myBox.setDim(2, 2, 2); myVol=myBox.volume(); myArea=myBox.area(); String...
2018-03-13 09:18:06
798
原创 C语言 产生随机数
需添加头文件stdlib.h。随机函数 int rand(void)。随机数范围0<rand()<RAND_MAX(RAND_MAX根据不同的计算机系统值不同)。使用rand()前,需先使用随机种子数函数 srand()设置随机数种子,若未设置,默认为1。生成某个范围内的随机数1.生成[0,N]之间的某个整数: rand()%(N+1);2.生成[N,M]之间的某个整数(M>...
2018-03-13 08:27:47
564
1
原创 C语言实现遗传算法
算法框架:1. GenerateInitialPopulation();//生成初代种群2. EvaluatePopulation();//评估种群3. GenerateNextPopulation();//产生下一代 1).SelectionOperator();//选择 2).CrossoverOperator();//交叉 RandomDi...
2018-03-12 17:49:52
3510
原创 JAVA面向对象程序设计,董小园 清华大学出版社 课后上机实验题代码 第1章
注意:文件名与公共类名一致1.1package test;public class java1_1 { public static void main(String[] args) { int a=Integer.parseInt(args[0]); if(a>12) a=a-12; System.out.println(a); }}1.2package test;public c...
2018-03-09 11:31:04
1968
原创 newton插值
运行环境 matlab2015aclcclearx=[0.0,0.1,0.2,0.3,0.4];y=[0.5000,0.5398,0.5793,0.6179,0.7554];n=5;a=zeros(n-1);f=zeros(n-1,1);ticfor i=2:n a(1,i)=(y(i)-y(i-1))/(x(i)-x(i-1));endfor
2017-10-15 21:01:12
349
原创 秦九韶算法
运行环境maltab 2015aclcclearn=4;%表达式最高次数a=zeros(n+1,1);b=zeros(n+1,1);c=zeros(n,1);a=[2,0,-3,3,-4];%表达式系数x=-2;%未知量x取值b(1)=a(1);for i=2:n+1 b(i)=x*b(i-1)+a(i);endp1=b(5);%函数值
2017-10-15 20:59:28
876
原创 拉格朗日插值
运行环境maltab 2015ax=[0,0.1,0.2,0.3,0.4];%结点x值y=[0.5000,0.5398,0.5793,0.6179,0.7554];%结点y值n=5;%结点个数x0=0.36;y0=0;for i=1:n l=1; for j=1:n if(i~=j) l=l*(x0-x(j))
2017-10-15 20:58:37
354
原创 银行家算法
运行环境VS 2010// banker.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#includetypedef struct Max1 // 资源的最大需求量{ int m_a;int m_b;int m_c;}Max; typedef struct Alloc
2017-10-15 20:56:21
1331
原创 进程调度模拟
运行环境 VS 2010// 进程调度.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include const int block_time=10; //定义时间片的长度为10秒 const int MAXPCB=100; //定义最大进程数typedef struct node //定义进
2017-10-15 20:53:55
1508
原创 栈的创建 以及基本操作出栈 入栈,判空
#include "stdafx.h"#include "malloc.h"#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OVERFLOW -2#define OK 1#define ERROR -1#define FALSE 0typedef int SElemType;typedef
2017-07-21 17:28:49
543
原创 二叉树的创建 以及先序,中序,后序输出
#include "stdafx.h"#include "malloc.h"typedef int Status;typedef char TElemType;#define OVERFLOW -2#define OK 1typedef struct BiTNode{TElemType data;struct BiTNode *lchild,*rchild;}B
2017-07-21 17:25:57
582
原创 有向图的创建(邻接矩阵)
// 图.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include"malloc.h"#define MAX_VERTEX_NUM 20#define ERROR -1#define OK 1typedef int VertexType ;typedef int InfoType;typedef int Stat
2017-07-21 10:17:28
8679
原创 集合的交 并 补运算
#include "stdafx.h"#define set_max_length 100typedef struct {int a[set_max_length];int length;}set;void Input(set &A){printf("Please enter the set length=");scanf("%d",&A.length);for
2017-07-21 10:15:07
3512
原创 稀疏矩阵运算器
// 稀疏矩阵计算器.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#define MAXSIZE 12500#define OK 1typedef int ElemType;typedef int Status;typedef struct{int i,j;ElemType e;}Triple;typedef
2017-07-19 20:30:33
905
原创 拓扑排序(C语言 邻接矩阵存储)
#include "stdafx.h"#include"malloc.h"#define MAX_VERTEX_NUM 20#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OVERFLOW -2#define OK 1#define ERROR -1#define FALSE 0typede
2017-07-19 20:26:43
1226
原创 C语言用链表实现插入排序
#include "stdafx.h"#includestruct student{ int score; struct student *next;};struct student *head=(struct student *)malloc(sizeof(struct student));struct student *head1=(struct student *
2016-11-13 16:43:29
1213
原创 C语言利用链表计算k^N 1<k<=9;
#include "stdafx.h"#includestruct number{ int num; struct number *next;};int _tmain(int argc, _TCHAR* argv[]){ int N,jinwei=0,value,a[100],sign=0,k; struct number *head,*temp,*p; h
2016-11-08 22:36:33
377
原创 C语言从文本文件中用字符串读取一行数据,然后再依次遍历字符串将字符串中数据分配。
#include "stdafx.h"#include#includeFILE *rfile=fopen("D:\\风中追风\\工作量表计算.csv","r");// 定义文件指针;int _tmain(int argc, _TCHAR* argv[]){ int i=0,number; double num; char p[5000],nam
2016-11-08 22:26:25
8087
原创 学生成绩计算修订
#include "stdafx.h"#include #include struct student{ int num; int score;};int sign[47];struct student stus[47];int stucount=47;double sum( ){ double s=0; for(int i=0;i {
2016-10-24 15:34:27
330
原创 利用结构体计算班级平均分,最高分,最低分,不及格等等
#include "stdafx.h"#include #include struct student{ int num; int score;};struct student stus[47]; //根据班级人数可修改,此处默认47人。int stucount=47;double sum( ){ double s=0; for(int i=0;i
2016-10-21 11:45:16
4284
原创 a c d…… AA AC AD 数据处理
#include "stdafx.h"#includeint _tmain(int argc, _TCHAR* argv[]){ char s[21]={"ACDEFGHIKLMNPQRSTVWY"},s1[400][2],str[5000]; int i=0,j=0,k=0,h=0; for(j=0,i=0;j { s1[j][0]=s[i]; if((j
2016-10-02 17:38:29
316
原创 数据处理(蛋白质序列)
#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){ int i,j,h; char str[5000]; FILE *readfile=fopen("F:\\风中追风\\蛋白质数据.txt","r"); FILE *writefile=fopen("F:\\风中追风\\shujujiesh
2016-10-01 19:36:31
2269
原创 小球随机出现在屏幕
#include#include#includevoid main(){ int i,posX,posY; while(true) { system("cls"); Sleep(50); posX=rand()%120+1; /*屏幕的行数*/ posY=rand()%30+1; /*屏幕的列数*/ for(i=0;i
2016-09-05 21:43:25
551
原创 出随机数利用rand函数与延迟时间函数
#include#include#includevoid main(){ while(true) { Sleep(500); /*暂停5s Sleep S大写 */ int num=rand()%47+1; printf("%4d",num); }} 注:此处的出的是1-47之间的随机数。
2016-09-05 21:35:07
1665
原创 跳动的字符 C
#include#includeint main(){ int i,posX=0,posY=0,dirX=1,dirY=1; while(1) { posX=posX+dirX; posY=posY+dirY; system("cls"); for(i=0;i printf("\n"); for(i=0;i
2016-09-01 12:54:20
2365
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人