0

16 個の配列があります (以下の例)。トーナメントの各試合では、2 つのレストランを表示し、お気に入りのレストランを選択するよう促し、負けたレストランをトーナメントから除外します。これはブラケット システムのようなものです。つまり、レストランは、他のすべてのレストランがそのラウンドの試合に登場するまで、別の試合に再び登場することはありません)。したがって、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 に答える