去年校招时的一道面试题,觉得蛮有意思,贴出来。

Question:

Spy start at a, during an interval he moves |b| to right when b >=0; moves |b| to left when b <0; I can ask the spy if he is in position x, if he is then I win.

Answer:

Here is how I analyze this problem:

1) First assume a = 0; then b could be 0, 1, 2….

i. |b| = 0 , I can guess 0 at first interval just caught the spy;

ii. |b| = 1 , then b could be 1 or -1, so I can guess 1 at first interval ; if not caught the spy, guess -2 at second interval and I will catch the spy;

iii. |b| = 2 , then b could be 2 or -2, so I can guess 2 at first interval ; if not caught the spy, guess -4 at second interval and I will catch the spy;

iv. ……

To sum it up ,I will take this list to catch the spy with n intervals,n start at 1:

0*1, 1*2, (-1)*3, (2)*4, (-2)*5, 3*6, (-3)*7, 4*8, (-4)*9 …… ((n/2)(-1)^n)*n;

2) But |a| can have many values not only zero ,when a=0,this is one-dimensional problem. We can regard (a, b) as a point in a Plane coordinate system .

  

This make the (a,b) in many squares, and we find the spy’s location from the most inside square to outside, and in every square we start at the point(|a|,0) as the red point showed in the picture. The same to the first problem is the time interval increases in Linear growth. And we can use the point’s value to calculate the location referenced to the point ,and can get the spy.

For example
1) (0,0): 0 + 0*1(this is the number of intervals);

2) (1,0): 1+ 0*2; (1,1): 1+ 1*3; (0,1): 0+ 1*4; (-1,1): -1+ 1*5……

3) As the picture shows;

An interview question from MicroStrategy的更多相关文章

  1. an interview question(1)

    声明:本文为博主原创文章,未经博主允许不得转载. 以下是英文翻译: warnning: Copyright!you can't reprint this blog when you not get b ...

  2. Core Java Interview Question Answer

    This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...

  3. shit LeetCode interview Question

    shit LeetCode interview Question https://leetcode.com/interview/1/ 有点晕,啥意思,没太明白,到底是要按什么排序呀? 去掉 标识符 不 ...

  4. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  5. an interview question(4)

    版权声明:本文为博主原创文章,未经博主允许不得转载. 写这篇博客前请让博主先吐糟下自己的PC. i3+2G内存+开了一上午=C盘剩下0字节+打开VS2012花了半个小时+一晚上的心情不好 吐槽完PC, ...

  6. an interview question(3)

    最近看了些C面试题顺便复习一下C语言,现贴一些出来和大家分享. #include <stdio.h> void main () { ,,,,};--------- *(ptr++)+=; ...

  7. an interview question(2)

    感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...

  8. Interview Question

    HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...

  9. Amazon Interview Question: Design an OO parking lot

    Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...

随机推荐

  1. vue-cli项目配置mock数据(新版本)

    最新的vue-webpack-template 中已经去掉了dev-server.js 但是要进行模拟后台数据的,如何模拟本地数据操作? 解决方法: dev-server.js 改用webpack-d ...

  2. Python程序,辅助微信跳一跳游戏介绍

    一.思路介绍 1. 通过Python自动手机截屏,并保存到电脑 2. 通过PhotoShop测量要跳的距离 3. 通过Excel计算按压时间 4. 通过CMD命令控制手机按压时间 二.实现方法详解 1 ...

  3. 使用UltraISO制作U盘启动

    下面给你提供是的一个万能的制作系统U盘的方法,用这个U盘你可以加载任何你想要的系统,即使是Linux系统都是可以,你需要做的就是下载安装软件,下载一个系统安装光盘的镜像文件,然后用软件导入到U盘就可以 ...

  4. 容器平台选型的十大模式:Docker、DC/OS、K8S谁与当先?

    首先我们来谈什么情况下应该使用Docker的问题   如图,左面是经常挂在嘴边的所谓容器的优势,但是虚拟机都能一一怼回去. 如果部署的是一个传统的应用,这个应用启动速度慢,进程数量少,基本不更新,那么 ...

  5. There is no Action mapped for namespace / and action name login. - [unknown location]

    (自己在浏览器中,直接进入项目的根目录,即 http://localhost:8080/ssh/  时便报错,web.xml文件已经配置了 欢迎页面 <welcome-file-list> ...

  6. 在Windows Server 2012启用或关闭Internet Explorer增强的安全配置

    在 Windows Sever 2012 中打开 IE 浏览器时,IE10 会出现[已启用 Internet Explorer 增强的安全配置]的提示信息. 在安全性等级中会设置以[高安全性],如果我 ...

  7. 关于lazyload图片延迟加载简单介绍

    LazyLoad大家再熟悉不过的一个jquery插件了,它可以延迟加载长页面中的图片. 也就是说在浏览器可视区域外的图片不会被载入,直到用户将页面滚动到它们所在的位置才会加载并显示出来,这和图片预加载 ...

  8. jQuery的删除的三种方法remove(),detach(),empty()

    remove()方法是从DOM中删除所有匹配的元素,包括匹配元素的子元素.但是他会有一个返回值, 返回值是一个指向已被删除的节点的引用,所以说,remove删除的元素,还可以再回收利用. var $l ...

  9. 读java并发编程笔记

    同步策略:在共享资源上面加锁 java监视器模式:class对象-与之对应的锁(内置锁)[对象锁与class锁] 执行策略: 取消策略: =============================== ...

  10. 使用JdbcTemplate访问数据库

    参考源端:https://blog.csdn.net/liaodehong/article/details/76974827 今天用Spring Boot访问一下数据库,并且把数据返回到页面中,进行增 ...