蓝月传奇装备价格表:pascal题目

来源:百度文库 编辑:高校问答 时间:2024/05/07 09:38:52
Problem
有一个由n*n*n个1*1*1的小立方体馅饼组成的大立方体馅饼.有一个虫子从坐标x1,y1,z1出发开始吃馅饼,

它只能向与它所在的小立方体相邻的小立方体馅饼前进,比如说当前虫子的坐标是1,1,1,它能到达的坐标是1,1,2和1,2,1和2,1,1.

当虫子还没有吃完所有的馅饼时,它都会继续前进.但是它不能到达它所经过了的小立方体.当虫子吃完所有的馅饼时,

它会在一个结束的位置x2,y2,z2.现在给定立方体大小n的和起始位置x1,y1,z1还有结束位置x2,y2,z2的值.

问是否虫子有可能从起始位置开始吃馅饼,当它吃完所有的馅饼之后到达结束位置?

如果可以输出"Yes"否则输出"No".

Input
第一行一个整数m表示测试数据的个数.

每个测试数据共三行,第一行一个数字n表示立方体的大小(1<=n<=10).

第二行三个数x1,y1,z1表示起始位置。

第三行三个数x2,y2,z2表示结束位置.

Output
如果可以输出"Yes"否则输出"No".

Sample Input
2
2
1 1 1
2 2 2
3
1 1 1
2 2 2

Sample Output
Yes
No

递归
eatnext(int[3] nowposition,int* pcounter,bool* presult)
{
if(presult=true)//避免无谓计算
return;
if(&pcounter!=m*m*m)//遍历所有可能当没有到最后一部
{
(&pcounter)++;
for(int i=0;i<3;i++)
{
nowposition[i]++;
if(check(nowposition))//use an array to store status of whether the cheese is eaten
eatnext(nowpostion,pcounter);
else
{
&presult=false;
return;
}
nowposition[i]--;
}
} else
{
if(nowposition == destination)
&presult=true;
}
return;
}
check(int[3] position)
{
//define an array:bool[m*m*m] store the status
//and initialize every item of array to be false;
//since be eaten, which is equal to be check for
//the time, so I waive to write the specific algorithsm
}