gpt4 book ai didi

algorithm - 单一候选人和多个面试官?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:07:33 28 4
gpt4 key购买 nike

有 1 个候选人要接受 n 个面试官的面试,因此总共需要 n 个连续的时间段,例如下表说明了四个面试官的可用性(I1、I2、I3、I4)在四个时隙(S1、S2、S3、S4)。表中的1表示相应的面试官在相应的时间段有空。

例如,第一个面试官 I1 在时间段 S1 和 S2 有空。

每个面试官只能参加一次面试,所有四个时段都应按顺序进行,如 S1->S2->S3->S4

在每个时段找到面试官的所有可能组合。这是图中的一个这样的例子,

enter image description here

算法

让我们考虑三组(挖掘和算法是不同的)

s1 =  array("I1","I2","I3")
s2 = array("I1","I2")
s3 = array("I2","I3")
interviewr_slot = array('slot1'=>s1,'slot2'=>s2,'slot3'=>s3,'slot4'=>null)

count = 3 //it can be any

stack = array()

possibility = array()

traced = array();

myoutput = rec_function(interviewr_slot)

function rec_func($interviewr_slot){
static slot = 0;

slot++;

possibility = interviewr_slot['slot']

if(possibility != null)
{
push(stack,traced)

reset(our_input);

our_input = array();
for( i = slot; i<= n+1, i++)
{
our_input[sloti] = si;
}

foreach(possibility as k=>v)
{

if(!in_array(v, trace))
{
array_push(traced, v)
rec_func(our_output)
}
}
}
else
{
push(output_array,traced)
}
slot--
traced = pop(stack)

our_output = json.stringify(output_array)
return our_output
}

最佳答案

使用PHP循环最终的数组并以相反的顺序跟踪每个数组元素以获得结果

<?php
$s1 = array("I1","I2","I3");
$s2 = array("I1","I2","I3");
$s3 = array("I1","I2","I3");
$interviewr_slot = array('1'=>$s1,'2'=>$s2,'3'=>$s3);
$flag = 0;
$len = count($interviewr_slot);
for($i = $len; $i>= 1; $i--){
if($flag == 0){
foreach ($interviewr_slot[$i] as $key => $value) {
$myarray[$key] = array($value);
}
$flag = 1;
}else{
$checkarray = $myarray;
unset($myarray);
$myarray = array();
foreach ($interviewr_slot[$i] as $key => $value) {
foreach($checkarray as $k=>$v){
if(!in_array($value, $v)){
array_push($v, $value);
array_push($myarray, $v);
}
}
}
}
}
var_dump($myarray);
?>

输出:

array (size=6)
0 =>
array (size=3)
0 => string 'I3' (length=2)
1 => string 'I2' (length=2)
2 => string 'I1' (length=2)
1 =>
array (size=3)
0 => string 'I2' (length=2)
1 => string 'I3' (length=2)
2 => string 'I1' (length=2)
2 =>
array (size=3)
0 => string 'I3' (length=2)
1 => string 'I1' (length=2)
2 => string 'I2' (length=2)
3 =>
array (size=3)
0 => string 'I1' (length=2)
1 => string 'I3' (length=2)
2 => string 'I2' (length=2)
4 =>
array (size=3)
0 => string 'I2' (length=2)
1 => string 'I1' (length=2)
2 => string 'I3' (length=2)
5 =>
array (size=3)
0 => string 'I1' (length=2)
1 => string 'I2' (length=2)
2 => string 'I3' (length=2)

关于algorithm - 单一候选人和多个面试官?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26850693/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com