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的更多相关文章

  1. Careercup | Chapter 1

    1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...

  2. Careercup | Chapter 3

    3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满 ...

  3. Careercup | Chapter 2

    链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow w ...

  4. Careercup | Chapter 8

    8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director ...

  5. Careercup | Chapter 7

    7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...

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

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

  8. CareerCup Chapter 4 Trees and Graphs

    struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),rig ...

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

随机推荐

  1. redis的字符串操作以及在django中的使用

    redis ----redis.MongoDB : 非关系型数据库 redis   存储在内存中 MongoDB 存储在硬盘中 l  简介 redis是一个key-value存储系统 , 支持持久化 ...

  2. POJ:2955-Brackets(经典:括号匹配)

    传送门:http://poj.org/problem?id=2955 Brackets Time Limit: 1000MS Memory Limit: 65536K Description We g ...

  3. Linux学习-备份策略

    每部主机的任务都不相同,重要的数据也不相同,重要性也不一样,因此,每个人的备份思考角度都不一样! 备份分为两大部分,一个是每日备份经常性变动的重要数据, 一个则是每周备份就不常变动的信息.这个时候我就 ...

  4. Mysql之查看数据库版本

    Mysql版本: 登入数据库的时候: select @@version; select version(); mysql> select @@version; +-----------+ | @ ...

  5. SpringDataJpa错误

    在运行项目的时候出现的错误如下: would dispatch back to the current handler URL [/save] again. Check your ViewResolv ...

  6. javascript 内置日期转换方法

    var d = new Date(); console.log(d); // 输出:Mon Nov 04 2013 21:50:33 GMT+0800 (中国标准时间) console.log(d.t ...

  7. 用上GIT你一定会爱上他

    前言 Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控 ...

  8. 初学-BeautifulSoup爬取豆瓣页面

    # -*- coding: utf-8 -*-import osimport urllibimport urllib2from bs4 import BeautifulSoup headers = { ...

  9. getattr、setattr、hasattr

    写一个演示类 class test(): title="验证getattr.setattr.hasattr方法" def run(self): return "run方法 ...

  10. mysql使用日常备忘

    批量插入数据时,如果主键是有业务意义的,并非自自增张,那么有可能在插入的数据中有与已存在的键值重复的,可以用如下方式来插入: INSERT IGNORE 当要插入一个数据时,插入的字段值中主键字段或唯 ...