由买买提看人间百态

topics

全部话题 - 话题: setvalue
1 (共1页)
P********l
发帖数: 452
1
来自主题: JobHunting版 - 问一个算法题
http://www.sureinterview.com/shwqst/545001
code:
public void findRange(double[] data, double rangeStart, double rangeEnd,
Mutable pStart, Mutable pEnd) {
pStart.setValue(-1);
pEnd.setValue(-1);
if (data == null || data.length == 0)
return;
int posStart = 0, posEnd = data.length - 1;
// find where the data roughly is.
int inRange = 0;
while (posStart <= posEnd) {
inRange = (posStart + posEnd) / 2;
if (data[in... 阅读全帖
a**U
发帖数: 115
2
来自主题: JobHunting版 - 一个C++的问题!
来源于面试题目,下面的code可以编译运行成功。关键是我觉得不应该编译运行成功,
请看下面我的comments。请高手指点。
#include
using namespace std;
class A
{
public:
virtual void test(){ cout <<"test A"< };
class B : public A
{
public:
virtual void test(){ cout <<"test B"< };
class C : public A
{
int value;
public:
C(){value = 1; }
virtual void test(){ cout <<"test C"< void accessValue() { cout << "value=" << value << endl; }
void setValue(int value){ this->value... 阅读全帖
t****a
发帖数: 1212
3
1、最简单办法是穷举, choose(m, n),但计算量太大
2、改进的办法是搜索,也就是给出coin集合的情况下,搜索另一个更好的coin集合。
可以一步步去搜索,前提是本题的解要满足局部最优解=全局最优解的条件(我还不会
证明这一点)。这个方法的计算复杂度已经大大低于1
3、更好的的办法是迭代法,通过n-1个coin的解来算n个coin的解
4、可能存在某个解析的方法(比如写出方程式,求偏导数=0,解方程组)一步计算出
所有的coin取值。方程组可以写出,但由于存在coin的取值全部为正整数的约束条件,
偏倒数=0无法得到正整数解。
呼唤高人来给出3、4的解法。
----------------------------------------
推不出策略3的解,所以我去尝试策略2:
首先要猜一个不错的初始取值,
然后在它的基础上进行搜索。
我猜的解是:
C_n = (M^(n-1))^(1/n)
C_{n-1} = (M^(n-2))^(1/(n-1))
...
C_1 = (C_2^0)^1 = 1
clojure code如下 (不包含搜索的部分)
(use 'clojure... 阅读全帖
s********x
发帖数: 914
4
来自主题: JobHunting版 - 狗狗家onsite面经
2吧
class CharNode {
private char value;
private CharNode next;
private CharNode previous;
public CharNode getPrevious() {
return previous;
}
public void setPrevious(CharNode previous) {
this.previous = previous;
}
public char getValue() {
return value;
}
public void setValue(char value) {
this.value = value;
}
public CharNode getNext() {
return next;
}
public void setNext(CharNode next) {
this... 阅读全帖
x***n
发帖数: 70
5
请看下面几行简单的代码:
1 TreeMap treeMap = new TreeMap Integer> ();
2 treeMap.put("Good", 136);
3 Map.Entry e = null;
4 e = treeMap.firstEntry();
5 e.setValue(23);
6 Set> el = treeMap.entrySet();
7 for( Map.Entry e1 : el ) {
8 e1.setValue(23);
9 }
第5行处,报错:java.util.AbstractMap$SimpleImmutableEntry.setValue(Unknown
Source)
但是,第8行处,是类似的操作,却能正常执行。
请问这是为什么?谢谢!
P**********c
发帖数: 3417
6
来自主题: JobHunting版 - on-site 面经
Singleton这个thinking in C++里有。写出来复习一下
方法一:
class Singleton{
static Singleton s;
int i;
Singleton(int x):i(x){}
Singleton& operator=(Singleton&);
Singleton(const Singleton&);
public:
static Singleton& instance() { return s;}
int getValue(){return i;}
void setValue(int x) {i=x;}
}
Singleton singleton::s(47);
方法二:
class Singleton{
int i;
Singleton(int x): i(x) {}
void operator=(Singleton&);
Singleton(const Singleton&);
public:
static Singleton& instance(){
... 阅读全帖
H***e
发帖数: 476
7
来自主题: JobHunting版 - 问两道facebook面试题
第二题,
用往上面反值的方法, 左右子树传值给parent node. 总复杂度为O(n).
inside a class:
BSTNode maxsumNode = null;
int maxValue = Integer.MIN_VALUE;
public void findMaxSumSubtree(BSTNode node, MutableInt sum) {
// base cases:
if (node == null) {
sum.setValue(0);
return;
}
// normal cases:
MutableInt leftSum = new MutableInt();
MutableInt rightSum = new MutableInt();
findMaxSumSubtree(node.left, leftSum);
findMaxSumSubtree... 阅读全帖
b******7
发帖数: 92
8
来自主题: JobHunting版 - 问一道题(5)
clear应该做不到O(1)。
我的想法是加设置commonValue,并加入时间戳区别setValue与setAllValues的调用先
后关系,若setValue比setAllValues先调用则返回hashmap中的值,否则返回
commonValue。具体code见http://blog.sina.com.cn/s/blog_979956cc0101hs1a.html
d***r
发帖数: 2032
9
来自主题: JobHunting版 - 一个C++题
下面这个code有错,因为m_value是const,不能赋值。能不能保留m_value的const属性
作其他改动使得code能够work呢?
class cTest
{
public:
cTest():{};
~cTest(){};
void SetValue( const double val ) const
{
m_value = val;
}
private:
double m_value;
};
int main( void )
{
cTest *t = new cTest();
t->SetValue(100);
delete t;
}
d**e
发帖数: 6098
10
来自主题: JobHunting版 - 星期一福利:某公司店面题
你的code似乎有个bug: while(true)没有条件退出,进入死循环.
我觉得你flip bit的那段code有些问题,它并没有正确地flip, list.get(i)是?的index
,用它来跟0/1比较应该是不正确的.
我把它改成这样,用shift bit来做,不知有没有更好的方法.
public static List genMatchers(String str) {
List results = new ArrayList();
if (str != null && str.length() != 0) {
List questionMarkPositions = new ArrayList();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c... 阅读全帖
f****r
发帖数: 311
11
来自主题: Java版 - Servlet & Cookie 求助
我在Servlet中使用Cookie时碰到一些问题,
向各位老大请教一下:
比如我先在Server端程序 P1 中定义:
C.setValue( A )
C.setMaxAge(-1)
response.addCookie( C )
这样设定了一个生命期随浏览器,
值为 A 的 Cookie C.
在Server端程序 P2 中我先
request.getCookie(C)
(当然是做循环找到想要的哪个Cookie )
然后试图更改该Cookie的MaxAge或Value,
用如下语句:
C.setValue( B ) -> 更改值
C.setMaxAge(0) -> 令其立即无效
但是我发现竟然在同一个浏览器中这个
改变都无法反映出来 !!!
请问是怎么回事?
( 是不是 更改之后还要在用addCookie给写回去?
要么就是Cookie一定要在 调用response.getwriter() 之前? )
多谢!
b***i
发帖数: 3043
12
来自主题: Programming版 - Java/C++的对象数组?
Java是不是
class Node{
private int value;
Node(int a){value=a;}
Node(){}
public void setValue(int a){value = a;}
}
Node[] all=new Node[size];
for(int i=0;i all[i]=new Node(i);
C++是不是不能这么做?是不是得如下,即必须使用默认的构造函数,无法像Java那样
可以先不构造
Node* all=new Node[size];
for(int i=0;i all[i]->setValue(i);
以上是微软的,因为没有实现可变大小的数组,这好像和C99有关?
s*****n
发帖数: 5488
13
来自主题: JobHunting版 - Amazon 电面
个人看法:
先定义出book对象,sort algorithm对象(应该是个decorator,就是可以pipeline到另
外一个alg对象上),然后需要定义less than, 定义adapter到STL quicksort。
public void sort()
{
call adaptoer method or obj from i to n.
for (i = k; i< booklist.count; i++)
{
if key[i] = key [j] continue;
else
if (mydecotor is not null)
mydecortor.setvalue(j, k);
mydecortor.sort();
}
大概框架应该是这样。
b*****e
发帖数: 22
14
来自主题: JobHunting版 - 一个C++的问题!
Probably due to the compiler you used. Empty base class optimization and
memory alignment all depend on compilers. Try print sizeof of all three
classes. Your compiler probably gives 4 bytes for all. I used GCC and got 4,
4,8 and therefore segfault at setValue.
d****o
发帖数: 1055
15
来自主题: JobHunting版 - 一道msft题
Describe a data structure for which getValue(int index), setValue(int index
, int value), and setAllValues(int value) are all O(1).
s********x
发帖数: 914
16
来自主题: JobHunting版 - 狗狗家onsite面经
大概是这个思路吧,没有测
public static TreeNode sortedArrayToBST(int[] a)
{
TreeNode root = new TreeNode();
int left = 0, right = a.length - 1;
Queue indexes = new LinkedList();
Queue nodes = new LinkedList();
nodes.add(root);
indexes.add(left);
indexes.add(right);
while (!indexes.isEmpty())
{
left = indexes.poll();
right = indexes.poll();
TreeNode p = nodes.poll();
int mid = left + (right - left) >>> 1;
p.setValue(a[mid]);
TreeNode leftChild = null, rightChild = nu... 阅读全帖
f*********d
发帖数: 140
17
来自主题: JobHunting版 - 问一道题(5)
Describe a data structure for which
getValue(int index)
setValue(int index, int value)
setAllwalues(int value)
are all O(1)
题目来之MS
A********d
发帖数: 558
18
来自主题: JobHunting版 - 新出炉的Google的offer+面经+包裹
Google:
虽然签了NDA,但是无所谓,不要举报就好了。
1. 一个背包有特定容量,和一些物品,每种物品所占空间不同,所代表的价值不同。
输入是背包容量 和 物品list,要求背包能装的最大的物品价值。
2. 给一串数字,和一个target,找两个数字,要求这两个数字的差最接近target。
3. 设计一个n乘n矩阵,有setValue, getRowSum和getMatrixSum.
4. 类似Path Sum和Path Sum II。
5. 找出两个不同字符的最长的连续字串。打印出所有的解。"yellow" => [ell, llo]
Facebook:
都是些leetcode的变种题,和好几道非常恶心的数学相关的题。
这次面了 Facebook, Uber, Airbnb, Google, Linkedin.
拿到了Google和Facebook的offer, 很可惜没有拿到uber和airbnb(还是很心仪这两家
hot startup的),Linkedin挂了但是感觉是个非常友好且大牛聚集的公司,相反,
Facebook挺傻逼的,虽然拿到了offer但面试体验不好,就像之... 阅读全帖
d******o
发帖数: 2489
19
来自主题: SanFrancisco版 - 请教如何给软件加个license (转载)
or
public string Read(string KeyName)
{
// Opening the registry key
RegistryKey rk = baseRegistryKey ;
// Open a subKey as read-only
RegistryKey sk1 = rk.OpenSubKey(subKey);
// If the RegistrySubKey doesn't exist -> (null)
if ( sk1 == null )
{
return null;
}
else
{
try
{
// If the RegistryKey exists I get its value
// or null is returned.
return (string)sk1.GetValue(KeyName.ToUpper());
}
/... 阅读全帖
e*****a
发帖数: 321
20
来自主题: Database版 - Access门外汉问题求教
做了一个form,有些text box, combo box什么的,想做个按钮,一click就能把上面的
那些值作为一个新record输入到一个table中去,看上去很简单的样子,然而。。。
给按钮写了个macro,用SetValue命令,死活run不了;又给按钮写了个SQL,用INSERT
INTO... VALUES( ),也不行,因为不知道怎么把form里的东西放进VALUES后面的括号
里去, FT to death...
请指教.
y*****g
发帖数: 13
21
我想在CODE中实现把一个ScrollBar拉到底的操作. 应该用什么method呢?
大概看了看JDOC,试了试setValue(getMaximum()).
不Work...:(
哪位拉兄弟一把...
r*****l
发帖数: 2859
22
To make it better, you can use interface, like
the following pseudo code:
public Interface ModifiableDouble {
public setValue(Double value);
pulibc Double getValue();
}
and have your wrapper class implement this
interface. The interface will be in your
method signature.
It seems redundant to use interface here, while
you will find the beauty of using it later.
e****e
发帖数: 418
23
This is the Java way to do.
public class test {
public class MyDouble {
double d;

protected MyDouble() {
this(0.0);
}

protected MyDouble(double value) {
d = value;
}

public void setValue(double newValue) {
d = newValue;
}

public double getValue() {
return d;
}

public String toString() {
return new Double(d).toStrin
g*****g
发帖数: 34805
24
Just use one level of indirection. e.g. have a class called Variable
class Variable {
boolean changed;
Object value;
public boolean setValue(Object value) {
if(changed) {
return false;
else {
this.value = value;
return true;
}
}
}
Then declare 10 instances.

3nd
o**1
发帖数: 6383
25
来自主题: Java版 - 这个闭包怎么写?
没有setKey这个东西。
只能setValue
w***o
发帖数: 6775
26
来自主题: Java版 - 多线程的一个基础问题
如果synchronize一个object的writing, 或者说setvalue. 那getvalue 或者reading,
是不是也要synchronize ? p.s. Object是mutable的
m*****k
发帖数: 731
27
来自主题: Java版 - JDK HashMap 的 Entry class
有一个int 成员 hash, 貌似没有用啊, 有人知道它留着何用?
static class Entry implements Map.Entry {
final K key;
V value;
Entry next;
final int hash;
/**
* Creates new entry.
*/
Entry(int h, K k, V v, Entry n) {
value = v;
next = n;
key = k;
hash = h;
}
public final K getKey() {
return key;
}
public final V getValue() {
return val... 阅读全帖
a***y
发帖数: 2803
28
f_setValue是一个函数名还是一个field的名字? 貌似和class有关.能不能把f_
setValue说明一下?
a***y
发帖数: 2803
29
f_setValue是一个函数名还是一个field的名字? 貌似和class有关.能不能把f_
setValue说明一下?
gw
发帖数: 2175
30
这个是我搞错了,那个文件名应该是file,虽然可以unmarshal,但结果不是真正想要的
datalist,有点奇怪
这个教程的例子也不行。
http://www.java2s.com/Code/Java/XML/UnmarshallwithJAXB.htm
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import... 阅读全帖
d*****l
发帖数: 8441
31
C#新手遇阻:
cuEnvKey = Registry.CurrentUser.OpenSubKey("Environment");
if (cuEnvKey != null && cuEnvKey.GetValue("PATH") == null)
cuEnvKey.SetValue("PATH", strPathToAdd, RegistryValueKind.ExpandString);
错误信息:
Unhandled Exception: System.UnauthorizedAccessException: Cannot write to the
registry key.
对于CurrentUser的环境设置,若无“PATH"值,想给其设某个值,但是却得到“无权限
”的错误。
如果说CurrentUser的程序不能更改“LocalMachine"的环境非常好理解,但是
难道作为CurrentUser运行的程序都不能改变CurrentUser环境下的PATH设置吗?
CurrentUser无Administrator权限。
哪位大牛指点一下,谢谢!
1 (共1页)