《Cracking the Coding Interview》——第8章:面向对象设计——题目6
2014-04-23 22:57
题目:实现一个数据结构来表示拼图游戏中的碎片。
解法:一个拼图块儿有四条边,每边只有凹凸平三种情况,当两块碎片拼接的时候,分为四个方向进行,块儿上的图案肯定也是判断是否能拼接的依据之一。所以就有了以下的表示方法,又一题做得云里雾里。话说这种题目在面试时如果真遇到,得写到什么程度的代码才算及格?
代码:
// 8.6 Design data structure to represent pieces in jigsaw puzzle. If possible please design an algorithm to solve it.
// I'll use the struct below to represent a piece, which has four sides, each one of which is either concave, convex or plain.
// And they must have some patterns on them, which can be considered as images.
// Solving a jigsaw can be done with DFS, which can be O(n!) in time scale, where n is total number of pieces.
// A possibl way is to do it in diagonal manner, starting from the left top corner.
// Like this:
// 0 1 2 3
// 1 2 3 .
// 2 3 ...
// 3 .....
// When doing the search, you have to check if a piece can be fit into a targetted position.
// a method fitsWith() will be used, parameters will included two pieces and a direction.
// For example, fitsWith(piece1, piece2, BOTTOM) means if piece2 fits on the bottom of piece1.
struct JigsawPuzzlePiece {
// left, top, right, bottom
// -1 for concave, +1 for convex, 0 for plain
int side[];
Image *image;
};
《Cracking the Coding Interview》——第8章:面向对象设计——题目6的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目10
2014-04-24 00:05 题目:用拉链法设计一个哈希表. 解法:一个简单的哈希表,就看成一个数组就好了,每个元素是一个桶,用来放入元素.当有多个元素落入同一个桶的时候,就用链表把它们连起来.由 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目9
2014-04-23 23:57 题目:如何设计一个内存文件系统,如果可以的话,附上一些代码示例. 解法:很遗憾,对我来说不可以.完全没有相关经验,所以实在无从入手.这题目应该和工作经验相关吧? 代码 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目8
2014-04-23 23:49 题目:有个棋牌游戏叫Othello,也叫Reversi.请看游戏规则.中文应该叫黑白棋吧,不常玩儿就是了. 解法:既然这题的规则很清楚,也很清楚,我就写了一个命令行的 ...
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目7
2014-04-23 23:38 题目:你要如何设计一个聊天服务器,有什么技术难点? 解法:这是基于工作经验的面试题吗?否则,一个new grad碰上这种题目能打点草稿也就算不错了. 代码: // 8 ...
随机推荐
- mysql5.6之前需要账号的安全加固
mysql5.6之前需要账号的安全加固 从5.7开始就不需要了. delete from mysql.user where user!='root' or host='localhost'; flus ...
- 木棒,POJ(1011)
题目链接:http://poj.org/problem?id=1011 解题报告: #include <cstdio> #include <cstring> #include ...
- C++STL之multiset多重集合容器
multiset多重集合容器 multiset与set一样, 也是使用红黑树来组织元素数据的, 唯一不同的是, multiset允许重复的元素键值插入, 而set则不允许. multiset也需要声明 ...
- 测试 jdbc 中连接关闭的时机
测试 jdbc 中连接关闭的时机 写一段程序,测试 jdbc 连接的关闭情况 /** * 测试 jdbc 连接的关闭情况 */ public static void testOpenCon(){ // ...
- 第4章 初识STM32—零死角玩转STM32-F429系列
第4章 初识STM32 集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/firege 本章参考资 ...
- fastjson 应用
fastjson优势就是解析快,用法和json-lib.jar差不多(如下图) 贴心的附上jar和反编译工具:https://pan.baidu.com/s/1iADAiFyoUZVBAFSPsIeY ...
- java乱码问题
我们知道JSP页面是需要转换为servlet的,在转换过程中肯定是要进行编码的.在JSP转换为servlet过程中下面一段代码起到至关重要的作用. <%@ page language=" ...
- java的八种基本数据类型
据说表格的方式一目了然 一. java数据类型的取值范围如下: 注意:long型后如果不加 L 则默认为int型,float型如果不加 F 则默认为double型: 注意!注意!注意 ...
- linux系统批量创建用户和生成8位随机密码
1.1 脚本案例 批量创建20个用户,用户名为user1-user20,并生成8位随机登录密码,用户组采用键盘输入的方式,并将用户名及登录密码保存到/tmp/create_user.txt普通文 ...
- 命名空间“Microsoft.Office”中不存在类型或命名空间名称“Interop”(是否缺少程序集引用?
在一个web项目中需要导出word打印,引用Microsoft.Office.Interop.Word后,在pages里使用正常,在app_code里新建类引用就报错. Report.cs里using ...