我有一个16的数组(下面的例子)。比赛的每场比赛包括显示两个餐馆,提示选择他最喜欢的餐馆,并从锦标赛中删除失败的餐厅。 它就像一个支架系统;即,在所有其他餐厅也出现在该轮的比赛中之前,餐厅不再出现在另一场比赛中)。所以从8场比赛开始,然后是4场,然后是2场。 除非餐馆数量等于16,否则不允许比赛开始。 我是C ++的新手。任何人都有一个体面的轮廓或我应该看的建议/路径?
string restaurants[] = {"Texas Roadhouse,","On The Border,","Olive Garden,","Panda Express,","Cracker Barrel,","IHOP,","Panda Express,","Pei Wei"};
答案 0 :(得分: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