0

我有一个 16 的数组(下面的示例)。比赛的每场比赛都包括展示两家餐厅,提示选择他最喜欢的一家,并从比赛中移除输掉的餐厅。它就像一个支架系统;即,在所有其他餐厅也出现在该轮比赛中之前,餐厅不会再次出现在另一场比赛中)。所以从 8 场比赛开始,然后是 4 场,然后是 2 场。除非餐厅数量等于 16,否则不要让比赛开始。我对 C++ 还是很陌生。有人有我应该看的不错的大纲或建议/路径吗?

string restaurants[] = {"Texas Roadhouse,","On The Border,","Olive Garden,","Panda Express,","Cracker Barrel,","IHOP,","Panda Express,","Pei Wei"};
4

1 回答 1

0

我只是要编写代码的要点,请进一步探索您希望如何实现它。

    //assume arr is the array of 16 and length =16 initially
  while(length >0)
    {
    for(i=0;i<length; i=i+2)
     {
      int first= rand % (16-i);

      int second=rand % (16-i);
        while(first==second)
         second=rand%16;

      int chosen=choose_restaurant(arr,first,second,length);
      //return either first or second, depending on what is chosen

      if(chosen ==first)
        remove_restaurant(arr,second,length);
      else
        remove_restaurant(arr,first,length);

     }
   length=length/2;
  }

//the remove_restaurant function must move the removed restaurant from the array
//And move the selected restaurant to the end 
于 2012-10-22T01:42:46.400 回答