21二次规划问题求解解

2016年全国高考数学(全国乙卷)第21题解答
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。1905人阅读
题目如上图所示。这里给出两种解法:第一种是自己想的,时间复杂度O(n^2);第二种方法实现的是实验室一个大牛的想法,时间复杂度O(n)。
代码如下:
void reorder1(NODE * root)
int sum = -1, changeTimes,
NODE * cur, *next, * stopN
NODE * this1;
static int insert_num = 0;
assert(root != NULL);
while (cur)
sum++;
cur = cur-&
changeTimes = sum / 2;
if (sum & 0x01)
changeTimes +=1;
insert_num = changeT
stopNode =
while (changeTimes--)
stopNode = stopNode-&
while (stopNode-&next )
this1 = stopNode-&
stopNode-&next = this1-&
insert_num++;
j = sum - insert_
while (j--)
cur = cur-&
next = cur-&
cur-&next = this1;
this1-&next =
void reorder2(NODE * rootp)
NODE * pHead1 = rootp, * pHead2 = rootp, *next1 , * next2, *pre2;
int changeTiems, sum = -1;
while (pHead1)
++
pHead1 = pHead1-&
changeTiems = sum / 2;
if (sum & 0x01)
changeTiems++;
while (changeTiems--)
pHead2 = pHead2-&
next2 = pHead2-&
pHead2-&next = NULL;
for (pre2 = NULL; (pHead2 = next2) != NULL;)
next2 = pHead2-&
pHead2-&next = pre2;
pre2 = pHead2;
next2 = pre2;
while ((pHead2 = next2) != NULL)
next2 = pHead2-&
next1 = pHead1-&
pHead1-&next = pHead2;
pHead2-&next = next1;
pHead1 = next1;
经过测试,运行无误!!!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:16902次
排名:千里之外
原创:16篇
评论:20条
(1)(3)(1)(2)(2)(2)(3)(1)(1)}

我要回帖

更多关于 遗传算法求解tsp问题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信