我需要为m个课程分配n个人,每个人指定他们的第一和第二个偏好,每个课程都有最多的人参加.每个人只能参加一门课程.该算法应该找到一个解决方案
我猜这不是一个不常见的问题,但搜索没有回复太有用,因此我决定推出自己的.这是我到目前为止所得到的:
由于最后一步,我仍然认为该算法不会找到问题的最佳解决方案.任何想法如何使这个更好?还有其他算法可以解决这个问题吗?
我知道没有简单的方法来进行多项功能分配VB,但是我的解决方案是 - 它是好的,你会怎样做得更好?
我需要什么(我将如何在python中做,只是一个例子)
def foo(a) ' function with multiple output
return int(a), int(a)+1
FloorOfA, CeilOfA = foo(a) 'now the assignment of results
Run Code Online (Sandbox Code Playgroud)
我是怎么用VB做的:
Public Function foo(ByVal nA As Integer) As Integer() ' function with multiple output
Return {CInt(nA),CInt(nA)+1}
End Function
Dim Output As Integer() = foo(nA) 'now the assignment of results
Dim FloorOfA As Integer = Output(0)
Dim CeilOfA As Integer = Output(1)
Run Code Online (Sandbox Code Playgroud) 数组和列表之间以及列表和标量上下文之间的区别已经在去年的Perl社区中进行了相当多的讨论(并且每年都是如此).我已阅读过chromatic和friedo的文章,以及这个推荐的修士节点.现在我想了解goatse运营商,中记录perlsecret.
这是我用来研究它的一些代码:
# right side gets scalar context, so commas return rightmost item
$string = qw(stuff junk things);
say $string; # things
# right side gets list context, so middle is list assigned in scalar context
$string = () = qw(stuff junk things);
say $string; # 3
# right side gets list context, so creates a list, assigns an item to $string2, and
# evaluates list in scalar context to assign to …Run Code Online (Sandbox Code Playgroud) 我正在尝试将在uintptr类型的变量中找到的值分配给Go中的uint64变量.运用
myVar = valFromSystem
Run Code Online (Sandbox Code Playgroud)
给我
不能在赋值时使用valFromSystem(类型uintptr)作为类型uint64
并尝试
myVar = *valFromSystem
Run Code Online (Sandbox Code Playgroud)
给我
valFromSystem的无效间接(类型uintptr)
有没有办法拉出valFromSystem指向的值来分配给myVar?
如何在tensorflow中执行以下操作?
mat = [4,2,6,2,3] #
mat[2] = 0 # simple zero the 3rd element
Run Code Online (Sandbox Code Playgroud)
我不能使用[]括号,因为它只适用于常量而不适用于变量.我不能使用切片函数,因为它返回一个张量,你不能分配张量.
import tensorflow as tf
sess = tf.Session()
var1 = tf.Variable(initial_value=[2, 5, -4, 0])
assignZerosOP = (var1[2] = 0) # < ------ This is what I want to do
sess.run(tf.initialize_all_variables())
print sess.run(var1)
sess.run(assignZerosOP)
print sess.run(var1)
Run Code Online (Sandbox Code Playgroud)
[2, 5, -4, 0]
[2, 5, 0, 0])
Run Code Online (Sandbox Code Playgroud) 我认为变量赋值是在给sess.run的列表中的所有操作之后完成的,但是下面的代码在不同的执行时返回不同的结果.它似乎在列表中随机运行操作,并在列表中运行操作后分配变量.
a = tf.Variable(0)
b = tf.Variable(1)
c = tf.Variable(1)
update_a = tf.assign(a, b + c)
update_b = tf.assign(b, c + a)
update_c = tf.assign(c, a + b)
with tf.Session() as sess:
sess.run(initialize_all_variables)
for i in range(5):
a_, b_, c_ = sess.run([update_a, update_b, update_c])
Run Code Online (Sandbox Code Playgroud)
我想知道变量赋值的时间.哪个是正确的:"update_x - > assign x - > ... - > udpate_z - > assign z"或"update_x - > udpate_y - > udpate_z - > assign a,b,c"?(其中(x,y,z)是(a,b,c)的排列)此外,如果有一种方法可以实现后一种分配(在完成列表中的所有操作后完成分配),请让我知道如何实现它.
以下代码有效.有没有一种更方便的方式,如果可能的话甚至是一个单行程?
const { nextUrl, posts } = await postService.getCommunityPosts(6);
this.communityPosts = posts;
this.nextUrl = nextUrl;
Run Code Online (Sandbox Code Playgroud)
我知道给出了结构化属性别名,但我不认为在这种情况下有帮助.MDN对此案没有任何说明.
该Perl6文档状态“默认情况下,参数绑定到他们的说法,并标记为只读。” 但是运行以下代码:
# Example 1
sub f1 ( $x ) { say $x.VAR.WHAT; say $x.WHAT; say $x }
f1(1);
Run Code Online (Sandbox Code Playgroud)
产量:
(Scalar)
(Int)
1
Run Code Online (Sandbox Code Playgroud)
而这段代码:
# Example 2
my $y := 1;
say $y.VAR.WHAT; say $y.WHAT; say $y;
Run Code Online (Sandbox Code Playgroud)
产量:
(Int)
(Int)
1
Run Code Online (Sandbox Code Playgroud)
这(Scalar)是我不理解的Example1的输出:我应该将Int 1参数绑定到标识符时,为什么会有标量$x?似乎该值已1“分配”给$x,而不是“绑定”了。
我搜索了如何在互联网上正确实现+运算符,我找到的所有结果都执行以下步骤:
const MyClass MyClass::operator+(const MyClass &other) const
{
MyClass result = *this; // Make a copy of myself. Same as MyClass result(*this);
result += other; // Use += to add other to the copy.
return result; // All done!
}
Run Code Online (Sandbox Code Playgroud)
关于这个"过程"我几乎没有问题:
以这种方式实现+运算符不是那么愚蠢,它在第一行调用赋值运算符(复制类),然后在返回中调用复制构造函数(由于返回的事实,它也复制了类)按价值,所以它破坏了第一个副本并创建了一个新的......坦白说,这并不是很聪明......)
当我写a = b + c时,b + c部分创建该类的新副本,然后'a ='部分将副本复制给自己.谁删除了b + c创建的副本?
有没有更好的方法来实现+运算符而不需要两次处理类,也没有任何内存问题?
提前致谢
有什么区别:
char fast_car[15]="Bugatti";
Run Code Online (Sandbox Code Playgroud)
和
char fast_car[15];
fast_car="Bugatti";
Run Code Online (Sandbox Code Playgroud)
因为第二个导致编译错误:
错误:从类型'char*'分配类型'char [15]'时出现不兼容的类型
虽然第一个工作正常.将数组中的字符串放在与数组初始化不同的位置会很有帮助.