2012-10-22 25 views
0

我有一个16的数组(下面的例子)。比赛的每场比赛都包括显示两家餐厅,提示选择他最喜欢的餐厅,并从比赛中移除丢失的餐厅。 它就像一个支架系统;即,在所有其他餐馆也出现在该轮的比赛中之前餐厅不会再出现在另一场比赛中)。因此,从8场比赛开始,然后是4场,然后是2场。 除非餐馆数量等于16,否则不要让锦标赛开始。 我对C++很新颖。任何人都有一个体面的大纲或建议/路径我应该看看?我将如何实施这样的比赛? C++

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

这似乎是功课。是吗?作为第一步,我建议提出一种用伪码编写的算法来解决这个问题。 – Alan

回答

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