2013年9月27日

笔试题 1.7 C++中定义一个空类,编译器都会做些什么

摘要: classEmpty{public:Empty();//缺省构造函数Empty(constEmpty&);//拷贝构造函数~Empty();//析构函数Empty&operator=(constEmpty&);//赋值运算符Empty*operator&();//取址运算符constEmpty*operator&()const;//取址运算符const};默认构造函数析构函数拷贝构造函数赋值运算符(operator=)取址运算符(operator&)(一对,一个非const的,一个const的)当然,所有这些只有当被需要才会产生。比如你定义了一个 阅读全文

posted @ 2013-09-27 20:59 馒头山小八路 阅读(519) 评论(0) 推荐(0)

笔试题 1.6 枚举+递归

摘要: 1, 这个题是个老题目啦:1~9个数字,每个数字只能出现一次,要求这样一个9位的数字:其第一位能被1整除,前两位能被2整除,前三位能被3整除,。。前9位能被9整除。#include#includeusing namespace std;vectoracc;bool used[10];void dfs(int k, long long a){ if(k>0 && a%k!=0){ return; } if( k == 9 ){ acc.push_back(a); return; } for(i... 阅读全文

posted @ 2013-09-27 20:43 馒头山小八路 阅读(207) 评论(0) 推荐(0)

笔试题 1.5 微软 2012 09.28 程设

摘要: 1,求取二叉数的深度; int depth(Node *root){ if(root == NULL) return 0; int left_depth = depth( root.left_child); int right_depth = depth( root.right_child); return (left_depth > right_depth) ? left_depth+1 : right_depth + 1; }2,利用天平砝码,三次将140克的盐 分成50、90克两份?砝... 阅读全文

posted @ 2013-09-27 17:48 馒头山小八路 阅读(255) 评论(0) 推荐(0)

面试题 1-5 等概率1和0的生成

摘要: 已知 f(x)生成0的概率为p,而生成1的概率为1-p;现在要求有f(x)来生成一个等概率产生0和2的 随机数发生器:设计相对简单,使用 g(x) = 1 - f(x), 那么g(x)生成 1的概率为p, 生成 0的概率为 1-p;则新构造的随机数发生器设计为h(x)int h(int x){ int sum = f(x) + g(x); if(sum == 0) return 0; else if(sum == 2) return 1; else{ return h(x) }}在前两步当中,生成0和1的概率均为 p(1-p); 而在最后... 阅读全文

posted @ 2013-09-27 09:46 馒头山小八路 阅读(454) 评论(1) 推荐(0)

导航