小编use*_*113的帖子

在声明之前不能使用局部变量

我正在尝试创建一个函数,但我收到一条错误消息.

public int[] genericSearch(int searchWidth, int startingRadius, int width, int height, Bitmap bitmap)
{
    //Generic function for finding the best path from a certain range
    if (startingRadius == -1)
        startingRadius = bitmap.Height() / 2;
Run Code Online (Sandbox Code Playgroud)

在声明之前不能使用局部变量'startingRadius'.

同样的问题也出现在位图变量中.通常在c ++中这种类型的声明会起作用; 但是,我不确定为什么它不在这里工作.

c# parameters scope function

19
推荐指数
1
解决办法
3万
查看次数

最大独立集算法

我不相信存在一种算法,用于在二分图中找到最大独立顶点集,而不是在所有可能的独立集中找到最大值的强力方法.

我想知道找到所有可能的顶点集的伪代码.

假设给出了一个带有4个蓝色顶点和4个红色的二分图.目前我会的

Start with an arbitrary blue,
  find all red that don't match this blue
  put all these red in Independent Set
  find all blue that dont match these red
  put these blue in Independent Set
  Repeat for next vertex in blue

Repeat all over again for all blue then all vertices in red.
Run Code Online (Sandbox Code Playgroud)

我知道这种方式根本不能给我所有可能的独立集合组合,因为在第一步之后我选择了所有不匹配的颜色顶点而不是逐步完成所有可能性.

例如,给出具有匹配的图表

B  R
1  1
1  3 
2  1
2  3
3  1
3  3
4  2
4  4

Start with blue 1
  Choose …
Run Code Online (Sandbox Code Playgroud)

algorithm graph-theory max np independent-set

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

大哦符号O((log n)^ k)= O(log n)?

在big-O表示法中O((log n)^k) = O(log n),k某些常量(例如,循环的对数),是真的吗?

我的教授告诉我,这种说法是正确的,但是他说这将在课程的后期证明.我想知道你们中是否有人能证明其有效性,或者有一个链接我可以确认是否属实.

big-o proof

6
推荐指数
2
解决办法
5882
查看次数

通过初始化列表调用另一个类的构造函数.有问题

这是我的示例代码:

#include <iostream>
using namespace std;

class Base
{
public:
    Base (int v, char z) {x=v;y=z;};
    int x;
    char y;
};

class Bar
{
public:
    Bar(int m, char n):q(m),s(n),base(q,s){};
    Base base;
    int q;
    char s;    
};

int main()
{
    Bar barObj(5,'h');    
    cout << barObj.base.x << barObj.base.y << endl;       
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么我得到了输出0http://ideone.com/pf47j

此外,在一般情况下,什么是创造另一个类的成员对象,并调用该对象的构造正确的方法,如上面做用的对象库class Base,里面class Bar

c++ constructor class object initializer-list

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

(log n)^ k = O(n)?对于k大于或等于1

(log n)^k = O(n)? For k greater or equal to 1.

我的教授在课堂上向我们介绍了这个陈述,但是我不确定函数是否具有O(n)的时间复杂度.甚至类似n^2 = O(n^2)的函数f(x)如何具有运行时复杂性?

至于声明它如何等于O(n)而不是O((logn)^ k)?

big-o logarithm proof notation

3
推荐指数
2
解决办法
6965
查看次数

VTKPNGWriter打印出黑色图像?

我正在使用ITK进行一些图像处理,然后使用VTK以.png格式打印结果,但输出图像始终为黑色.

目前,我正在使用itk :: ImagetoVTKImageFilter(在我的代码中为typedeffed to ITKtoVTKFilterType)将itk :: Image转换为vtk :: vtkImageData.

ITKtoVTKFilterType::Pointer itk2vtkGray = ITKtoVTKFilterType::New();
itk2vtkGray->SetInput(grayBinary);  //grayBinary is of type itk::Image<unsigned short, 2>
itk2vtkGray->Update();

vtkSmartPointer<vtkImageData> grayVTK = vtkSmartPointer<vtkImageData>::New();
grayVTK->SetExtent(extent);
grayVTK->SetSpacing(m_spacing);
grayVTK->SetScalarTypeToUnsignedShort();
grayVTK->SetNumberOfScalarComponents(1);
grayVTK->AllocateScalars();
grayVTK->DeepCopy(static_cast<vtkImageData*>(itk2vtkGray->GetOutput()));
//grayVTK = itk2vtkGray->GetOutput();
Run Code Online (Sandbox Code Playgroud)

我甚至使用以下代码确认我的VTK ImageData包含255或0的值.

int *dims = grayVTK->GetDimensions();

std::cout << "Dims: " << " x: " << dims[0] << " y: " << dims[1] << " z: " << dims[2] << std::endl;
std::cout << "Number of points: " << grayVTK->GetNumberOfPoints() << std::endl;
std::cout << "Number of …
Run Code Online (Sandbox Code Playgroud)

c++ png vtk itk

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

在给定最大匹配的情况下找到二分图的最小顶点覆盖

我似乎找到了一个算法,但我很难理解它,我想知道你们中是否有人知道算法的通用轮廓.

这是我在第2页找到的算法的链接

http://www.cse.iitb.ac.in/~sundar/cs435/lecture23.pdf

algorithm graph set matching bipartite

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

声明指针的方法?

为什么以下代码编译:

int main()
{
   int j = 1;
   int *jp = &j;

   cout << "j is " << j << endl;
   cout << "jp is " << jp << endl;
   cout << "*jp is " << *jp << endl;
   cout << "&j is " << &j << endl;
   cout << "&jp is " << &jp << endl;
}
Run Code Online (Sandbox Code Playgroud)

但不是吗?

#include <iostream>
using namespace std;
int main()
{
   int j = 1;
   int *jp;
   *jp =& j; // This is the …
Run Code Online (Sandbox Code Playgroud)

c++ pointers

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

c#使用未分配的局部变量或对象实例未设置为引用?

以下是一段似乎没有在c#中工作的代码,尽管它在c ++中似乎是可以接受的.C#似乎有不同的对象实例化标准.

                IList<PointF> vertices = null;

                float radius = (int)(bitmap.Width/3);

                for (double theta = 0; theta < 2 * 3.14; theta += 0.1)
                {
                    PointF temp = new PointF();
                    temp.X = centre.X + radius*((float)(Math.Cos(theta)));
                    temp.Y = centre.Y + radius*((float)(Math.Sin(theta)));
                    vertices.Add(temp);
                }
Run Code Online (Sandbox Code Playgroud)

IList是一个接口,而PointF是一个结构.Tbh我不知道实现接口和类时的差异.

如果我没有为顶点指定"null",则代码不会编译.但是,如果我分配null然后在运行时我得到一个错误"对象实例未设置为对象的引用"(因为顶点被声明为null).我怎样才能解决这个错误?

c# null object instantiation

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