小编Ste*_*oft的帖子

表示多图(C++)的良好数据结构

描述无定向多图(针对速度和内存进行了优化)的最佳数据结构是什么?

边缘列表是不合适的,因为获取顶点的邻居经常在我的代码中发生.

邻接列表并不好,因为我必须保留有关被访问边的信息,并且当访问1到3的边时(比如我遍历1的邻居并找到导致3并具有权重的边w),我必须在3的邻居列表中找到相同的边缘以将其标记为已访问,这很慢.

我已经考虑过邻接矩阵当每个小区将是set<Edge>其中Edge是表示关于如果顶点被访问信息的结构,重量边缘等.然而,具有当graph[0][1][i]为已访问我无法设置相同边缘中graph[1][0]的边缘没有线性搜索.

在表示多图时,有什么好的方法和技巧吗?我不想要第三个图书馆解决方案boost::AdjacencyList; 我必须自己写.

编辑:对不起有误.这是大学的练习,我只能使用标准库来完成它.该图有约束:0 <n≤300 - 顶点数0 <m≤20000 - 边数1≤w≤500

我的内存限制为32 MB,时间限制为0.5秒(我必须遍历DFS).

c++ graph data-structures

10
推荐指数
1
解决办法
2567
查看次数

Gradle构建错误:org.gradle.buildexceptionreporter Gradle版本使用2.14.1

Error:11:25:12.400 [ERROR] [org.gradle.BuildExceptionReporter] 
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] **FAILURE: Build failed with an exception.**
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] 
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] * **What went wrong:**
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] **java.lang.NullPointerException (no error message)**
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] 
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] *** Exception is:**
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] **java.lang.NullPointerException**
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.TreeSnapshotRepository.removeTreeSnapshotUsage(TreeSnapshotRepository.java:85)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.CacheBackedFileSnapshotRepository.remove(CacheBackedFileSnapshotRepository.java:47)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1$1.run(CacheBackedTaskHistoryRepository.java:84)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.Factories$1.create(Factories.java:22)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
11:25:12.401 [ERROR] [org.gradle.BuildExceptionReporter] …
Run Code Online (Sandbox Code Playgroud)

android build.gradle android-gradle-plugin

2
推荐指数
1
解决办法
2984
查看次数

通过引用传递为右值

当我尝试通过引用调用move成员时,编译器会抛出一个错误,但是当我重新定义成员函数以传递值时,它会起作用.

我可以不在我的成员函数中使用引用传递作为右值吗?

#include <iostream>
#include <string>

class Screen{
private:
    std::string contents;
    using position = std::string::size_type;
    position height,width,cursor_position;
public:
    Screen() = default;
    Screen& move(position&,position&); // Pass by reference
};

Screen& Screen::move(position& row,position& col)
{
    (*this).cursor_position = (row * width) + col;
    return *this;
}

int main() {
    Screen myScreen;
    myScreen.move(4,0); // This line gives a compile error
}
Run Code Online (Sandbox Code Playgroud)

c++ pass-by-rvalue-reference

1
推荐指数
1
解决办法
61
查看次数