您的位置:首页 > 产品设计 > UI/UE

Buiding in Sandbox--2016微软预科生技术岗笔试题四--Java

2016-04-07 10:21 501 查看
问题:

Little Hi is playing a sandbox voxel game. In the game the whole world is constructed by massive 1x1x1 cubes. The edges of cubes are parallel to the coordinate axes and the coordinates (x, y, z) of the center of each cube are integers.

At the beginning there is nothing but plane ground in the world. The ground consists of all the cubes of z=0. Little Hi needs to build everything by placing cubes one by one following the rules:

The newly placed cube must be adjacent to the ground or a previously placed cube. Two cubes are adjacent if and only if they share a same face.

The newly placed cube must be accessible from outside which means by moving in 6 directions(up, down, left, right, forward, backward) there is a path from a very far place - say (1000, 1000, 1000) in this problem - to this cube without passing through ground or other cubes.

Given a sequence of cubes Little Hi wants to know if he can build the world by placing the cubes in such order.

输入

The first line contains the number of test cases T(1 <= T <= 10).

For each test case the first line is N the number of cubes in the sequence.

The following N lines each contain three integers x, y and z indicating the coordinates of a cube.

For 20% of the data, 1 <= N <= 1000, 1 <= x, y, z <= 10.

For 100% of the data, 1 <= N <= 100000, 1 <= x, y, z <= 100.

输出

For each testcase output “Yes” or “No” indicating if Little Hi can place the cubes in such order.

样例提示

In the first test case three cubes are placed on the ground. It’s OK.

In the second test case (1, 3, 2) is neither on the ground nor adjacent to previous cubes. So it can’t be placed.

In the last test case (2, 2, 1) can not be reached from outside. So it can’t be placed.

样例输入

3

3

1 1 1

1 2 1

1 3 1

3

1 1 1

1 2 1

1 3 2

17

1 1 1

1 2 1

1 3 1

2 3 1

3 3 1

3 2 1

3 1 1

2 1 1

2 1 2

1 1 2

1 2 2

1 3 2

2 3 2

3 3 2

3 2 2

2 2 2

2 2 1

样例输出:

Yes

No

No

package hihocoder;

import java.util.Scanner;

public class Main {
boolean mark=true;
int count=0;
public static void main(String args[]){
Main m=new Main();
m.getInput();
}

public void getInput(){
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
count=0;
mark=true;
int num=in.nextInt();
int[]X=new int[num];
int[]Y=new int[num];
int[]Z=new int[num];
for(int j=0;j<num;j++){
int x=in.nextInt();
int y=in.nextInt();
int z=in.nextInt();
setArray(x,y,z,X,Y,Z);
}
if(mark){
System.out.println("Yes");
}else
System.out.println("No");
}
in.close();
}
public void setArray(int i,int j,int k,int[]X,int[]Y,int[]Z){
boolean mark1=false;
X[count]=i;
Y[count]=j;
Z[count]=k;
count++;
if(k>1){
for(int q=0;q<count-1;q++){
int i1=Math.abs(i-X[q]);
int i2=Math.abs(j-Y[q]);
int i3=Math.abs(k-Z[q]);
if(i1+i2+i3==1){
mark1=true;
break;
}
}
mark=mark1&&mark;
}
}
}


以上程序自己在eclipse中测试,都没有问题,但是提交都显示WA,为什么呢?自己的测试集不够吗?欢迎各路大神指教!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: