我编写战舰c ++,但它有问题 [英] I program battleship c++ but it has problem
问题描述
您好
我想为船舶游戏编程:根据以下文字
例如我们有4艘船,我们有一张桌子4 * 4我们想要放根据列和行的容量在此表中发货。
因此我使用了回溯并且这种形状是真实的答案。
http://upload.ugm.ac.id/434shape.docx
当我们让船舶进入此订单时,这是真正的答案:船舶1-ship2- ship3-ship4
但如果船舶有此订单:船舶2-ship1- ship3-ship4答案是错的。
实际上如果输入形状符合下面的形状,我的回答是错误的。
http://upload.ugm.ac.id/434shape.docx [ ^ ]
任何人都可以帮助我吗?>
我的代码是:
void General :: Ship( int count, int k, int n) // count< = k
{
int lenght;
lenght = L [count]; // L contan船长度意味着例如2:是3-2-2-2
for ( int x = 1 ; x< = n; x ++)
{
for ( int y = 1 ; y< = n; y ++)
{
if (IsOkhorizontal(x,y,lenght,n)== 1 )
{
Horizontally(x,y,lenght,count,n) ;
if (count == k)
{
Print();
}
else
发货(计数+ 1,k,n);
}
if (IsOkvertical(x,y,lenght,n)== 1 )
{
垂直(x,y,lenght,count,n);
if (count == k)
{
Print();
}
else
发货(计数+ 1,k,n);
}
}
}
}
这个例子我们应该打电话给船(1,4,4)
谢谢
谢谢任何人
我明白了。 ...
Hello
I want to program for ship game : according to below text
For example we have 4 ship and we have a table 4*4 and we want put ship in this table according to capacity of column and row.
Therefore I used backtracking and for this shape is true answer .
http://upload.ugm.ac.id/434shape.docx
It is true answer when we have ships enter with this order : ship 1-ship2- ship3-ship4
But if ships had this order : ship 2-ship1- ship3-ship4 the answer will be wrong.
Actually if input shape was according to below shape , my answer is wrong.
http://upload.ugm.ac.id/434shape.docx[^]
Can any body help me?
My code is :
void General::Ship(int count,int k,int n) // count <= k
{
int lenght;
lenght=L[count]; // L contan ships length means for example 2:is 3-2-2-2
for (int x=1;x<=n;x++)
{
for(int y=1;y<=n;y++)
{
if (IsOkhorizontal(x,y,lenght,n)==1 )
{
Horizontally(x,y,lenght,count,n);
if(count==k)
{
Print();
}
else
Ship(count+1,k,n);
}
if (IsOkvertical(x,y,lenght,n)==1)
{
Vertically(x,y,lenght,count,n);
if(count==k)
{
Print();
}
else
Ship(count+1,k,n);
}
}
}
}
For this example we should calling ship(1,4,4)
thanks
thanks anyone
I understand ....
这篇关于我编写战舰c ++,但它有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!