单个候选人面对多名面试官?

3
有1个候选人需要被n个面试官面试,因此需要n个连续的时间段,下表展示了四个时间段(S1,S2,S3,S4)内四个面试官(I1,I2,I3,I4)的可用性情况。表中的1表示相应的面试官在相应的时间段内可用。
例如,第一个面试官I1在时间段S1和S2可用。
每个面试官只能进行一次面试,并且所有四个时间段应按顺序进行,如S1->S2->S3->S4
找到每个时间段中面试官的所有可能组合。 以下是其中一个示例:
算法: 我们以三个集合为例(dig和algo不同)。
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
    }

1
很好。恭喜?你有问题吗? - Marc B
是的,正在寻找最佳选项。 - user3752338
1
不,它只是针对一个单独的候选人,正如所述。 - Mr X
修改你的“算法”描述,它太糟糕了。 - Karoly Horvath
任何可以提供的帮助 - user3752338
2个回答

1
使用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);
?>

output:

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)

如何在JavaScript中使用这个逻辑 - user3752338

1

我认为你必须使用搜索树。这里有一个C#实现。

class InterviewSequence
{
    List<string> Slots;
    List<string> Sequences;
    int iNumbers; // numbers of interviews/slots

    public InterviewSequence()
    {
        this.Slots = new List<string>();
        this.Slots.Add("ABCD"); // Available interviewers
        this.Slots.Add("AB"); // do..
        this.Slots.Add("BC");
        this.Slots.Add("BCD");
        this.iNumbers = this.Slots.Count;
        this.Sequences = new List<string>();
        string slotAviability = this.Slots[0];
        foreach (char c in slotAviability)
        {
            string sequence = "" + c;
            NextInterview(0, sequence);
        }
        foreach (string seq in this.Sequences)
        {
            Console.WriteLine(seq);
        }
    }

    private void NextInterview(int slot, string sequence)
    {
        string slotAviability = this.Slots[slot++];
        foreach (char c in slotAviability)
        {
            // Interviewer not booked in the sequence?
            if (sequence.IndexOf(c) < 0)
            {
                string val = sequence + c;
                if (slot == this.iNumbers - 1) // Last slot?
                {
                    this.Sequences.Add(val);
                }
                else
                {                       
                    NextInterview(slot, val); // goto next slot
                }
            }
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接