TSP问题:模拟退火算法 /* 利用模拟退火算法求解TSP问题 */#include"iostream"#include"ctime"#include"cmath"#define MAX 10000#define INF 10000000#define E 0.000000001 // 迭代误差 #define L 20000 // 迭代次数 #define AT 0.999 // 降
TSP问题(34个省会城市):遗传算法 # -*- encoding: utf-8 -*-# 利用遗传算法求解TSP问题import randomimport mathSCORE_NONE = -1class Life(object): """个体类""" def __init__(self, aGene=None): self.gene = aGene self.sco
N皇后问题:基于局部搜索策略的高效算法 基于局部搜索策略的高效算法,求解5000个皇后问题,单核时间控制在15分钟以内。代码中有打印棋盘形式的代码,可选择运行。在冲突检测部分,提供了两种方法,包括暴力循环方法和数组方法,大家可以用来参考学习。
全排列问题,输出所有排列结果 /*全排列问题C++代码输入:全排列元素数量 n n个需要排列的字符输出:该n个字符的全排列序列*/#include <iostream>using namespace std;void swap(int &a, int &b) { //交换 int temp = a; a = b; b = temp;}vo...
MAC终端命令大区 目录操作命令名功能描述使用举例mkdir创建一个目录mkdir dirnamermdir删除一个目录rmdir dirnamemvdir移动或重命名一个目录mvdir dir1 dir2cd改变当前目录cd dirnamepwd显示当前目录的路径名pwdl
Print Pattern Write a program that reads an interger n, and then displays 2^0, 2^1, ... 2^i-1, ... 2^0 for each line, where i = n...1.For example, if n=4, the pattern is as follow: 1 2 4 8 4 2 1 1 2 4 2 1
The GCD and LCM Give you two integers, and calculate their GCD(Greatest Common Divisor) and LCM(Least Common Multiple). If both of them are positive, print the GCD and LCM. If some are invalid(zero or negative), print invalid.