小编jus*_*tik的帖子

C++,std :: transform按索引替换项目

int v1和v2有2个未排序的向量,其中v1包含v2的子集

v1: 8 12 4 17
v2: 6 4 14 17 9 0 5 12 8 
Run Code Online (Sandbox Code Playgroud)

有没有办法,如何用v2中的位置索引替换v1的项目?

v1: 8 7 1 3
Run Code Online (Sandbox Code Playgroud)

用循环编写这样的算法是没有问题的......

但有没有使用std :: transform的解决方案?

c++ replace transform vector indices

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

Matlab,如果条件没有循环

在循环内有A(n,1),B(n,1)和以下条件

for i=1:m
   if ( A(i, 1) > error )
      B(i,1) = 0;
   else
      B(i,1) = exp (-A(i,1) / 100)
   end
end
Run Code Online (Sandbox Code Playgroud)

如何在不使用任何循环的情况下重写此条件?有可能是这样的

 if ( A(:, 1) > error )
      B(:,1) = 0;
   else
      B(:,1) = exp (-A(:,1) / 100)
 end
Run Code Online (Sandbox Code Playgroud)

matlab loops for-loop if-statement conditional-statements

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

算法,找到局部/全局最小值,2 个变量的函数

让我们有一个有两个变量的函数:

 z=f(x,y) = ....
Run Code Online (Sandbox Code Playgroud)

你能建议我任何合适的方法(简单的算法,快速收敛)来计算某些间隔的局部极值或全局极值吗?

感谢您的帮助。

algorithm function minimum

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

C++,指向函数的指针作为新类型

在C++ 2003中,typedef只能用于完整类型.因此,不允许创建指向函数的指针和通用T作为类型:

template <typename T>
typedef T(*f_function)(T, T, T);
Run Code Online (Sandbox Code Playgroud)

有没有办法如何使用语法在C++ 2003或C++ 0x中回避这个问题

using (*f_function)(T, T, T); // something like that
Run Code Online (Sandbox Code Playgroud)

我想使用指向函数fff的指针作为类成员

template <typename T>
class A
{
public:
    f_function fff;

    A() {fff = NULL;}
    A( f_function pf){fff = &pf;}
};

template <typename T>
T f1(T x, T y, T z) {   return x + y + z;}

template <typename T>
T f2(T x, T y, T z) {   return x - y - z;}
Run Code Online (Sandbox Code Playgroud)

并在构造函数中初始化其值.随后:

int main()
{
A <double> …
Run Code Online (Sandbox Code Playgroud)

c++ function-pointers parameter-passing generic-programming

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

C++,如何从迭代器返回对成员变量的引用

从std :: vector派生出以下B类

class B: public std::vector <unsigned int>
{
    public:
            B() : std::vector <unsigned int> ( 0 ) {}
};
Run Code Online (Sandbox Code Playgroud)

和A类如下:

class A
{
    private:        
            B b;    
    double x;

public:
    B & getB () {return b;}
    B const & getB() const {return b;}

    bool operator() ( const A & a ) const
            {
                    return a < a.x;
            }
};
Run Code Online (Sandbox Code Playgroud)

为什么不可能从它的迭代器中返回存储在std :: list中的某个对象A的变量b的引用(以及如何做到这一点)?

int main ()
{
std::set <A > alist;
std::set <A> ::iterator i_alist = alist.begin();

for (; i_alist …
Run Code Online (Sandbox Code Playgroud)

c++ iterator reference vector set

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

Java:从Runnable返回结果

假设以下简化示例.设B表示处理某些栅格数据的类:

import java.awt.image.BufferedImage;

public class B implements Runnable{
    private boolean c;
    private Runnable f;

    public B (boolean c_, Runnable f_) { c = c_; f = f_;}

    public BufferedImage process() {
            //Some operations
            BufferedImage output = null;
            if (c) output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
            return output;
    }

    public void run() { process();}
}
Run Code Online (Sandbox Code Playgroud)

处理()方法可以但可能不产生输出评价者.由于计算成本,该过程在单独的线程中运行.

设A表示将在其中运行过程的类.它还包含一些等待线程完成后的后处理步骤:

import java.awt.image.BufferedImage;

public class A {
    public A(){}
    public void compute() {
            boolean c = true;
            B b = new B( c, …
Run Code Online (Sandbox Code Playgroud)

java multithreading return runnable

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

线段相交、数值稳定测试

我需要对二维中的 2 条线段相交进行精确且数值稳定的测试。有一种可能的解决方案检测 4 个位置,请参见下面的代码。

getInters ( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double & x_int, double & y_int  )
{
    3: Intersect in two end points,
    2: Intersect in one end point,
    1: Intersect (but not in end points)
    0: Do not intersect 

unsigned short code = 2;

//Initialize intersections
x_int = 0, y_int = 0;

//Compute denominator
    double denom =  x1 * ( y4 - y3 ) + …
Run Code Online (Sandbox Code Playgroud)

c++ testing numerical intersection

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