Careercup | Chapter 6
6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are given 31 dominos, and a single domino can cover exactly two squares. Can you use the 31 dominos to cover the entire board? Prove your answer (byproviding an example or showing why it's impossible).
很巧妙的反证。
6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.
得到1:装满3---从3倒进5---装满3---从3倒进5,此时3的瓶子里装的就是1.
得到2:装满5---从5倒进3,此时5的瓶子里装的就是2;
得到3:装满3;
得到4:装满5--从5倒进3--倒空3--从5倒进3(3里面有2)---装满5---从5再倒进3(倒进了1),现在5的瓶子里装的就是4;
得到5:装满5;
得到6:得到1之后再装满5就行;
得到7,得到2之后再装满5;
得到8, 装满3和5;
6.4 A bunch of people are living on an island, when a visitor comes with a strange order: all blue-eyed people must leave the island as soon as possible. There will be a flight out at 8:00pm every evening. Each person can see everyone else's eye color, but they do not know their own (nor is anyone allowed to tell them). Additionally, they do not know how many people have blue eyes, a/though they do know that at least one person does. How many days will it take the blue-eyed people to leave?
没想到。应该从最基础的case开始。
6.6 There are 100 closed lockers in a hallway. A man begins by opening all 100 lockers. Next, he closes every second locker. Then, on his third pass, he toggles every third locker (closes it if it is open or opens it if it is closed). This process continues for / 00 passes, such that on each pass i, the man toggles every ith locker. After his 100th pass in the hallway, in which he toggles only locker #100, how many lockers are open?
都是好题。
微软面试题(考思维)
1. 有两个房间,一间房里有三盏灯,另一间房有控制着三盏灯的三个开关, 这两个房间是分割开的,从一间里不能看到另一间的情况。 现在要求受训者分别进这两房间一次,然后判断出这三盏灯分别是由哪个开关控制的。 有什么办法呢?
进入开关房, 打开a灯,约5分钟后关掉,打开b灯;马上进入灯房,亮着的灯为b灯,灯泡有点热的是a灯,另一个就是c灯;
关键是利用到灯泡发热。
2. 你让一些人为你工作了七天,你要用一根金条作为报酬。金条被分成七小块,每天给出一块。 如果你只能将金条切割两次,你怎样分给这些工人?
1+2+4
3. 假设你有一个用1001个整数组成的数组,这些整数是任意排列的,但是你知道所有的整数都在1到1000(包括1000)之间。此外,除一个数字出现两次外,其他所有数字只出现一次。假设你只能对这个数组做一次处理,用一种算法找出重复的那个数字。如果你在运算中使用了辅助的存储方式,那么你能找到不用这种方式的算法吗?
可以用求和+减法,也可以用xor。
Careercup | Chapter 6的更多相关文章
- Careercup | Chapter 1
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...
- Careercup | Chapter 3
3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满 ...
- Careercup | Chapter 2
链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow w ...
- Careercup | Chapter 8
8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director ...
- Careercup | Chapter 7
7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...
- CareerCup Chapter 9 Sorting and Searching
9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. ...
- CareerCup chapter 1 Arrays and Strings
1.Implement an algorithm to determine if a string has all unique characters What if you can not use ...
- CareerCup Chapter 4 Trees and Graphs
struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),rig ...
- Careercup | Chapter 5
5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to inse ...
随机推荐
- [译]The Python Tutorial#6. Modules
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使 ...
- GoF23种设计模式之行为型模式之命令模式
一.概述 将一个请求封装为一个对象,从而可以使用不同的请求对客户端进行参数化.对请求排队或记录请求日志,以及支持撤销的操作. 二.适用性 1.当抽象出待执行的动作以参数化某个对象的时候. 2.当需要在 ...
- 中移物联网onenet入门学习笔记1:资料获取
onenet学习资料.视频.例程汇总:https://open.iot.10086.cn/bbs/thread-977-1-1.html onenet开发文档:https://open.iot.100 ...
- STM32——PWM基本知识及配置过程
将通用定时器分为四个部分: 1,选择时钟 2,时基电路 3,输入捕获 4,输出比较 本节定时器PWM输出主要涉及到定时器框图右下方部分,即输出比较部分 和上一讲相同,时基时钟来源于内部默认时钟 对此有 ...
- /dev/sda is apparently in use by the system; will not make a filesystem here!解决方法
/dev/sda is apparently in use by the system; will not make a filesystem here! 翻译:系统显然在使用,不会在这里做文件系统 ...
- HTML5之中国象棋,附带源码!
好久没写随笔了,好怀恋2013年的日子,因为现在不能回到过去了! 再见了 感谢你为我做的一切! 进入正题:HTML5之中国象棋 很小就会下象棋了, 这是象棋的测试地址:点击我吧 然后点击里面的象 ...
- provider:命名管道提供程序,error:40 - 无法打开到SQL Server的连接 (Microsoft
最近一直在配置服务器, 这当中最头疼的就是配置数据库 我们用的是SQL Server 数据库 2008 版本,数据库配置完之后从另一台电脑访问数据库死活连接不上,提示信息如下 " 无法连接到 ...
- PHP函数参数传递(相对于C++的值传递和引用传递)
学语言学得比较多了,今天突然想PHP函数传递,对于简单类型(基本变量类型)和复杂类型(类)在函数参数传递时,有没有区别呢,今天测试了下: 代码如下: <?php function test($a ...
- selenium - 常用浏览器操作方法
常用浏览器操作 (1)初始化浏览器会话: from selenium import webdriver driver = webdriver.Chrome() (2)浏览器最大化操作: driver. ...
- day01_10.for循环
for和while都是一种循环 解释:所有循环的共同点 画图详解 在一条数轴上,循环就是有起始点($i=0); 有结束点($i<=10);有步长($i++); 每走一个相应的步长,就执行一次代码 ...