由买买提看人间百态

topics

全部话题 - 话题: elses
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
s*****y
发帖数: 897
1
来自主题: JobHunting版 - 问道google面试题
写了一个基于tree的,插入的原则是
1.比较最高位的digit,大的插入右边,小于或者等于的插入左边
2.如果最高位相等,比较combine 2个数的结果,哪个大决定插入左边或者右边
所有node都插入到树的最低层。
建完tree后,traverse tree按照right, current left的顺序,测了一下案例,似乎是
对的,
//int A[] = {2, 3, 5, 78 }; //pass
//int A[] = {2, 3, 89, 897 }; //pass
// int A[] = {3,3,43}; //pass
int A[] = {9, 98, 987, 902, 399, 380}; //pass
//int A[] = {900, 9001, 2}; //pass
// int A[] = {2, 3, 89,94, 899 }; //pass
// int A[] = {2, 3, 89, 897 }; //pass
// int A[] = {2, 3, 5... 阅读全帖
h*z
发帖数: 33
2
根据Young tableau的思路下了以下算法。
写的有点罗嗦。简单说就是在Young tableau里保持两个索引(a,b), (c,d), a >= c, b
<= d, 这两个中有一个是第k步最大的和。下面有些condition case省略了不可能的情
况。第4步,k是一个常数。25行O(m)。可以把横竖换一下变成O(n)。
M(x, y)
1 return A[x] + B[y]
LARGEST(k)
1 (a, b) = (1, 1)
2 (c, d) = (1, 1)
3 (e, f) = (1, 1)
4 for i = 1 to k
5 if a = c and b = d then
6 (e, f) = (a, b)
7 if a = m and b = n then
8 // last element, stop
9 else if a = m and b < n then
10 (a, b) = (1, b + 1)
11 (c, d) = (1, d + 1)
1... 阅读全帖
k***t
发帖数: 276
3
来自主题: JobHunting版 - 面经
#3 GetMedian() 感觉写得有点复杂,insert()应该还可以简化。
==============
#include
#include
#include
#include
using namespace std;
class Median {
public:
Median() : maxhc(0), minhc(0) {}
~Median() {}
void insert (int v) {
if (maxhc==minhc) {
if (maxh.empty() || maxh.top()>=v)
_enQ(true, v);
else _enQ(false, v);
} else if (maxhc>minhc) {
if (maxh.top()>v) {
_enQ(false, _deQ(true));
_enQ(true, v);
} e... 阅读全帖
m********0
发帖数: 2717
4
来自主题: Stock版 - USD/CHF跌的跟大便一样
送你一个EA,(copyright "Andrew Whaley")
专门从MT下载intraday data的。
别搞这么恶心的标题了。
//+---------------------------+
//| Historic Data Dumping EA |
//+---------------------------+
#property copyright "Andrew Whaley"
extern int min_year = 2010;
extern int max_year = 2012;
// Global scope
int handle;
int init()
{
int p = Period();
string pd;
if (p == 1) pd = "M1";
else if (p == 5) pd = "M5";
else if (p == 15) pd = "M15";
else if (p == 30) pd = "M30";
else if (p == 60) pd = "H1";
else if ... 阅读全帖
D*****r
发帖数: 6791
5
来自主题: TrustInJesus版 - 诺贝尔奖得主比昂松的名言
http://www.gutenberg.org/files/37726/37726-h/37726-h.htm
IN GOD'S WAY
SCHOOL-DAYS
I.
In the melting snow on the hill-side by the sea, in the last rays of the
evening sun, stood a boy of fourteen, awestruck. He looked toward the west,
out across the sea; he looked toward the east, over town and shore and the
broad hills; in the background still higher peaks rose far away in the clear
sky.
The storm had lasted a long time; it had been more terrible, too, than any
the old people could remember. In ... 阅读全帖
g***l
发帖数: 18555
6
我找到了一个SCRIPT LOGIN的
USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint in... 阅读全帖
w*******e
发帖数: 269
7
来自主题: Military版 - 雷某事件责任分析:pseudocode
if(雷某没有进入足浴店)
警察抓错人、负全责
else if(雷某进入过足浴店、但没有进行性交易)
警察抓错人、负全责
else if(雷某有性交易、但没有插入){
法律尚未明确为嫖娼、警察未必完全正当
if(雷某没有戴过套)
警察撒谎
else if(雷某出来后、警察才宣布抓人)
警察执法不当、不在现场抓捕、而且未掌握实质证据、就抓人后找证
据、程序违法。
else{
警察事前从足浴店获取雷某性交易信息、有钓鱼执法、串通足浴店、
包庇黄色场所之嫌

}else if(雷某有插入、有嫖娼){
雷某嫖娼行为已经犯法、警察执法符合法律、但程序仍然可能不合法
if(警察有殴打雷某){
if(警察有正式告知雷某,警察乃系便衣,正在执行何等任务){
if(雷某继续反抗... 阅读全帖
S**I
发帖数: 15689
8
来自主题: JobHunting版 - [合集] 问个google面试题
☆─────────────────────────────────────☆
Bayesian1 (Jason) 于 (Tue Jun 21 01:52:31 2011, 美东) 提到:
Given a binary tree, find 2 leaf nodes say X and Y such that F(X,Y) is
maximum where F(X,Y) = sum of nodes in the path from root to X + sum of
nodes in the path from root to Y - sum of nodes in the common path from root
to first common ancestor of the Nodes X and Y
☆─────────────────────────────────────☆
SecretVest (Secret Vest) 于 (Tue Jun 21 04:01:30 2011, 美东) 提到:
not hard if someone is used... 阅读全帖
K*********n
发帖数: 2852
9
来自主题: JobHunting版 - 问个二叉树删除结点的问题
Node *del(Node *tree, int n){
Node *nodeFather = tree -> father;
if (tree -> val == n){
if (tree -> left == NULL && tree -> right == NULL){ // a leaf
if (nodeFather -> left == tree){
nodeFather -> left == NULL;
free(tree);
return nodeFather;
}else{
nodeFather -> right == NULL;
free(tree);
return nodeFather;
... 阅读全帖
l****c
发帖数: 782
10
来自主题: JobHunting版 - facebook的面试题
第二题,小测试过了,大测试Time Limit Exceeded怎么回事呢
class Solution {
public:
bool isInterleave(string s, string s1, string s2, int s_index, int s1_index,
int s2_index)
{
if (s_index == s.size()) {
if((s1_index == s1.size())&&(s2_index == s2.size()))
return true;
else
return false;
}
else {
if (s1_index==s1.size()&&s2_index==s2.size())
return false;
else if (s1_index==s1.size()) {
if (s[s_index]==s2[s2_index]&&(isInterl... 阅读全帖
f*********d
发帖数: 140
11
//我上个代码吧, 没有测试过, 有错误或者bug请指出。。。
//这里假设所有节点的值都不一样, 如果存在一样的节点值, 需要一点修改。。。
struct BSTNode {
BSTNode* left;
BSTNode* right;
int val;
}
//print open interval (min_val, max_val) in r
void PrintBST(BSTNode* r, int min_val, int max_val)
{
if(r == NULL) return;
if(r->val <= min_val) PrintBST(r->right, min_val, max_val);
else if(r->val >= max_val) PrintBST(r->left, min_val, max_val);
else {
PrintBST(r->left, min_val, r->val);
cout << r->vale;
PrintBST(r-... 阅读全帖
J**9
发帖数: 835
12
来自主题: JobHunting版 - 一道A家店面题求解
How about this direction?
=====================================
/// array is sorted in Ascending order
int binarySearchAscending(int array[], int key, int low, int high)
{
int mid;
if(!array|| (low>high))
return -1;

while(high >= low)
{
mid = low+(high-low)/2;
if(key < array[mid])
high = mid-1;
else if (key > array[mid])
low = mid+1;
else
return mid;
}

return -1;
}
/// array is sorted in D... 阅读全帖
f*******t
发帖数: 7549
13
来自主题: JobHunting版 - 2道算法题。 求教大家!
找出了一年多前写的逆波兰处理算数表达式的代码,强烈建议有兴趣的自己实现一下:
#include
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
struct Token {
bool isNum;
int num;
char op;
Token();
Token(const Token& t);
};
Token::Token()
{
isNum = false;
num = 0;
op = 0;
}
Token::Token(const Token& t)
{
isNum = t.isNum;
num = t.num;
op = t.op;
}
Token *getToken(const char expr[], int& idx)
{
Token *res = NULL;
while(expr[idx] == ' ')
... 阅读全帖
B**********2
发帖数: 923
14
来自主题: JobHunting版 - Quantcast悲剧面经
首先感谢microleo,给我推荐
电话两轮,一个聊天,一个简单的电面。
Coding Test 一轮,题目为Spread Sheet,大家可以自行Google
得到Positive Feedback
5月8号 On site
分别两个工程师两个项目经理
鉴于每个人多聊了一会我以前的Project,所以每个人问1到3个问题不等。
----------------- 割割割割割割割割 -----------------------------
Q: Spread Sheet 如果太大,不能整个Load进内存来处理。但是可以有多个
机器按照一定的信息读本机文件。假设Spread Sheet每个连通片的计算量
一个机器能够处理
A: Virtually的建立无向连通图,用DFS获得连通片,每个连通片交给一个主机来计算
----------------- 割割割割割割割割 -----------------------------
Q: 给一个森林和已知两个节点,求最近公共祖先,如果没有,返回NULL
A: 我说啥语言没有什么区别,先上伪码,MIT Press Algorithm ... 阅读全帖
N******t
发帖数: 43
15
贴代码,如有错误,请私信。
/**
* Implement insert and delete in a trinary tree.
*
*/
public class TrinaryTree {
/**
* define a trinary tree's node
*
*/
static class TreeNode{
public int val; // node's value
public TreeNode left, right, mid; // represent left, right, middle
node
public TreeNode(int v){
this.val = v;
left = null;
right = null;
mid = null;
}
}
TreeNode root;

public TrinaryTre... 阅读全帖
m*****n
发帖数: 2152
16
现在这个是真DP了吧,可以输出任意长度的电话号码。
void buildTable(vector > &lookup_table)
{
for(int i=0; i<10; i++)
{
vector v;
if(i==0) {v.push_back(4); v.push_back(6);}
else if(i==1) {v.push_back(6); v.push_back(8);}
else if(i==2) {v.push_back(7); v.push_back(9);}
else if(i==3) {v.push_back(4); v.push_back(8);}
else if(i==4) {v.push_back(0); v.push_back(3); v.push_back(9);}
// else if(i==5) {}
else if(i==6) {v.push_back(0); v.push_back(1); v.pu... 阅读全帖
a***e
发帖数: 413
17
leetcode上的,感觉如果选择的语言有split这个function,就会好写很多,比如C#和
Java。
C++就麻烦些。而且选择是algorithm 的find还是string的find也很不同。
面试时碰到这类题能说我这道题用C#或者Java,其他用C++行么?其实现在主要用C#,
但C++是总共用得最久的。Java感觉和C#很像,但实际工作中没用过,也不想为面试而
学。多谢
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
两个C++的
1. string simplifyPath(string path) {
vector a;
int n = path.size();
for (int i = 0; i {
string t;
... 阅读全帖
E**********r
发帖数: 2743
18
haha,我在逞强而已了,其实太吵的歌我听不下去的,我喜欢旋律好走心的歌,
Metallica有首经典的“Nothing Else Matters”还挺不错的。
“Nothing Else Matters”,http://www.youtube.com/watch?v=Tj75Arhq5ho
So close no matter how far
Couldn't be much more from the heart
Forever trusting who we are
And nothing else matters
Never opened myself this way
Life is ours, we live it our way
All these words I don't just say
And nothing else matters
Trust I seek and I find in you
Every day for us something new
Open mind for a different view
And nothing else matter... 阅读全帖
D*****r
发帖数: 6791
19
来自主题: TrustInJesus版 - For the Liberty of Unlicenc'd Printing
A SPEECH OF Mr. JOHN MILTON
For the Liberty of VNLICENC'D PRINTING,
To the PARLAMENT of ENGLAND.
______________________________________________________________
This is true Liberty when free born men
Having to advise the public may speak free,
Which he who can, and will, deserv's high praise,
Who neither can nor will, may hold his peace;
What can be juster in a State then this?
... 阅读全帖
o****i
发帖数: 1706
20
【 以下文字转载自 Programming 讨论区 】
发信人: ouyadi (可乐会捂帮帮众), 信区: Programming
标 题: Java代码,老是compile出错,大家帮我看看哪错了。。。
发信站: BBS 未名空间站 (Wed Apr 27 16:58:23 2011, 美东)
我在git上push到学校的服务器后编译老是不通过,错误如下,麻烦大家帮我查下原因
,谢谢啦!
javac -classpath /usr/share/junit/lib/junit.jar -d classes -sourcepath .
Iterator.java List.java TestUpTree.java UpTree.java
UpTree.java:34: type Iterator does not take parameters
public class NIterator implements Iterator{
^
UpTree.java:104: type Iterator does not take parameters
pub... 阅读全帖
o****i
发帖数: 1706
21
我在git上push到学校的服务器后编译老是不通过,错误如下,麻烦大家帮我查下原因
,谢谢啦!
javac -classpath /usr/share/junit/lib/junit.jar -d classes -sourcepath .
Iterator.java List.java TestUpTree.java UpTree.java
UpTree.java:34: type Iterator does not take parameters
public class NIterator implements Iterator{
^
UpTree.java:104: type Iterator does not take parameters
public class SetIterator implements Iterator{
^
TestUpTree.java:51: type Iterator does not take parameters
Iterator it = up.m... 阅读全帖
a*****g
发帖数: 19398
22
来自主题: Programming版 - 计算围棋棋盘合法图案的源代码
#!/usr/bin/env pike
// legal.pike - Count the number of legal go boards.
// Copyright 2005 by Gunnar Farneb?ck
// [email protected]
/* */
//
// You are free to do whatever you want with this code.
//
//
// This program computes the number of legal go board configurations
// for a rectangular board of a given size. It is efficient enough to
// handle boards up to 8x8 within minutes and up to 11x11 in less than
// 24 hours (on a fast computer). For rectangular boa... 阅读全帖
K****n
发帖数: 5970
23
看,这就是google这个网站全部的源代码:
大哥大嫂过年好!
content="text/html; charset=UTF-8">Google