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
以上程序自己在eclipse中测试,都没有问题,但是提交都显示WA,为什么呢?自己的测试集不够吗?欢迎各路大神指教!
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,为什么呢?自己的测试集不够吗?欢迎各路大神指教!
相关文章推荐
- Qt Quick 简介
- 3.8.2 smtpd_chat_query和smtpd_chat_replay:与smtp客户端交互
- [na][tools]快速ping网段工具-QuickPing
- [转]MyBatis传入多个参数的问题 - mingyue1818
- [转]MyBatis传入多个参数的问题 - mingyue1818
- UIViewContentMode各类型效果
- 【Tips】【UE】总结自己常用的UltraEdit使用技巧
- CppCMS1.0.3 Build by VS2012
- 如何在Android Studio里设置一个项目所用的Build Tool版本?
- 干货技巧!有哪些实用秘诀可以帮助UI/UX设计师自我提升
- 3.7.4 event_request_timer:安排定时事件
- iOS 系统自带UItableviewcell上添加其它控件 不需要自定义cell 简单粗暴
- EASYUI 1.4版 combobox firefox 下不支持中文检索的问题
- UIView层次管理bringSubviewToFront,sendSubviewToBack
- 求第k个排列组合(Permutation Sequence)
- js数组实际上是key-value对,长度可无限增长
- 《iOS Human Interface Guidelines》——Text Field
- Information Acquisition
- $(".className").attr("disabled", "true")
- 分布式Unique ID的生成方法