翻硬币问题
#include "stdafx.h"
#include <iostream>
using namespace std;
void solve(int m)
{
bool * CurrentSurface = new bool[m];
for (int i=0;i< m; i++)
CurrentSurface=true;
int turnTimes=0;//翻转次数
bool bSuccess=false;
do
{
for(int i=0;i<m;i++)
{
for(int j=0;j<(i+1)/2;j++)
{
//turnCoin(j,i-j+1);
bool temp=CurrentSurface[j];
CurrentSurface[j]=!CurrentSurface[i-j];
CurrentSurface[i-j]=!temp;
}
if((i+1)%2==1)
CurrentSurface[i/2]=!CurrentSurface[i/2];
turnTimes=turnTimes+1;
bSuccess=true;
for(int n=0;n<m;n++)
{
if(CurrentSurface[n]==false)
{
bSuccess=false;
break;
}
}
if(bSuccess)
break;
}
}
while(!bSuccess);
printf("翻转的总次数是:%d\n",turnTimes);
delete[]CurrentSurface;
}
int main()
{
int CoinCount=1;
while(CoinCount>0)
{
printf("请输入硬币 的总数:");
scanf("%d",&CoinCount);
solve(CoinCount);
}
return 0;
}
谁能给讲解 讲解 i,j ,m ,n 还有那几个for循环和if 语句的 意思啊 不懂 哎