本题的提示要用拓扑
本人想着试着用拓扑,但是发现要求的数组太大,没法构建相应的边,故放弃了
因此想了另一个办法,代码如下
#pragma warning(disable:4996)
#include<stdio.h>
using namespace std;
#define maxn 1000001
int maxx;
struct listnode
{
listnode*pre;
int indu_num = 0;//记录indu指向的j,即i->j
listnode() {}
listnode(int n, listnode*p = NULL) :indu_num(n), pre(p) {}
};
struct p_list
{
listnode*head, *trail;
int flag = 1,length=1;
void init();
// ~p_list();
p_list() { init(); }
void insert(int&out);
// p_list&operator=(p_list&a);
};
void p_list::init()
{
head = new listnode();
trail = new listnode();
head->pre = trail;
trail->pre = NULL;
}
void p_list::insert(int&out)//越先进入的元素,越靠近队尾
{
listnode*p = new listnode(out);
p->pre = head->pre;
head->pre = p;
}
p_list edge[maxn];
int dsf(listnode*p, int i)//i是上一层的值
{
auto q = p->pre;
int count=1;
while (q != edge[i].trail)
{
if(edge[i].flag==0){
count+=edge[i].length;break;
}
count+

这篇博客探讨了如何尝试用拓扑方法解决清华数据结构在线评测系统(OJ)上的旅行商问题(TSP),但由于数据规模限制而放弃。作者提出了一种新的思路,利用flag变量避免重复走过的边,当某点所有出边都被访问后,将其flag设为0,以保持路径长度不变。博主分享了他认为最快运行速度的代码截图。

1232

被折叠的 条评论
为什么被折叠?



