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

问题:
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:

  1. 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.

  2. 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,为什么呢?自己的测试集不够吗?欢迎各路大神指教!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值