china_sjc
unread,Aug 6, 2008, 5:34:22 AM8/6/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 中国矿业大学徐海学院算法课程
#include <iostream.h>
int marble[6];
const int limit[]={3,4,5,4,6,5};
bool half(int d,int next)
{
if(d==0)
return true;
if(next==0)
return false;
int i;
for(i=marble[next-1];i>=0;i--)
{
if(d>=i*next)
{
marble[next-1]-=i;
if(half(d-i*next,next-1))
return true;
marble[next-1]+=i;
}
}
return false;
}
int main()
{
int i,test=1,sum=0;
for(i=0;i<6;i++)
{
cin>>marble[i];
if(marble[i]>limit[i])
{
marble[i]=limit[i]-(marble[i]-limit[i])%2;
}
sum+=marble[i]*(i+1);
}
while(sum!=0)
{
if(sum%2==0&&half(sum/2,6))
{
cout<<"Collection #"<<test++<<":"<<endl;
cout<<"Can be divided.\n"<<endl;
}
else
{
cout<<"Collection #"<<test++<<":"<<endl;
cout<<"Can't be divided.\n"<<endl;
}
sum=0;
for(i=0;i<6;i++)
{
cin>>marble[i];
if(marble[i]>limit[i])
{
marble[i]=limit[i]-(marble[i]-limit[i])%2;
}
sum+=marble[i]*(i+1);
}
}
return 0;
}