HDU 1029 一道微软面试题】的更多相关文章

http://acm.hdu.edu.cn/showproblem.php?pid=1029 给定一个数组,其中有一个相同的数字是出现了大于等于(n + 1) / 2次的.要求找出来. 1.明显排序后,中间那个位置的就是ans,复杂度O(nlogn) 2. 考虑分治 假设那个人是ans,那么对于其他人,我都用一个ans去代替它.就是他们两个一起死了,从这个数组中删除. 那么我最后剩下的那个人当然还是ans,因为它人数都大于一半了. 同时删除了两个没关的人,那更好了.如果枚举的那两个人都是ans,…
每日微软面试题——day 6(打印所有对称子串) 分类: 2.数据结构与算法2011-08-14 14:27 9595人阅读 评论(15) 收藏 举报 面试微软string测试systemdistance <以下微软面试题全来自网络> <以下答案与分析纯属个人观点,不足之处,还望不吝指出^_^> <出处:http://blog.csdn.net/zhanxinhang> 题:1.如何判断一个字符串是对称的?如a,aa,aba. 2.如何利用2函数找出一个字符串中的所有对…
HDU 1029 题目大意:给定数字n(n <= 999999 且n为奇数 )以及n个数,找出至少出现(n+1)/2次的数 解题思路:n个数遍历过去,可以用一个map(也可以用数组)记录每个数出现的次数, 若次数一旦达到(n+1)/2,即输出a[i] 注意能出现(n+1)/2次数的最多只有一个 /* HDU 1029 *Ignatius and the Princess IV --- dp */ #include <cstdio> #include <cstring> #in…
有一道 JavaScript 面试题. f = function () { return true; }; g = function () { return false; }; (function() { if (g() && [] == ![]) { f = function () { return false; }; function g() { return true; } } })(); console.info(f()); 首先看前两行 var f = function () {…
Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1029 Appoint description:  jehad  (2014-05-27) gscsdlz  (2015-04-14) System Crawler  (2015-09-05) Description "OK…
一道sql面试题(查询语句)   id name age 1  a        11 2  b        11 3  c        12 4  d        13 5  e        12 . . . 查询age唯一的那一个 这个应该怎么写 满意答案 热心问友 2010-10-14 select * from table1 where id not in (select age from table1 group by age having count(1)>1)   --Up…
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But you can never pass the next test." feng5166 says. "I will tell you an odd number N, and then N integers. There will be a special integer among t…
一道经典面试题-----setTimeout(function(){},0) 转载: http://www.w3cfuns.com/notes/17398/e8a1ce8f863e8b5abb530069b388a158/page/3.html#tagsbar 先看题: for (var i = 0; i < 3; i++) { setTimeout(function() { console.log(i); }, 0); console.log(i); } 结果是:0 1 2 3 3 3 很多公…
无意间,看到这么一道Python面试题:以下代码将输出什么? def testFun():    temp = [lambda x : i*x for i in range(4)]    return temp for everyLambda in testFun():    print (everyLambda(2)) 脑中默默一想,这还用说么,肯定是: 0 2 4 6 最后一看答案,竟然是: 6 6 6 6 于是带着怀疑的心态(其实是不服输,不认错),打开编辑器,快速一敲,果然是. ​ 怀疑…
这段时间一直在研究设计模式,在看工厂模式的时候,看到一段代码 VehicleFactory.prototype.createVehicle = function ( options ) { if( options.vehicleType === "car" ){ this.vehicleClass = Car; }else{ this.vehicleClass = Truck; } return new this.vehicleClass( options ); }; 对这段代码最后的…