g**e 发帖数: 6127 | 1 diff oil上次我记得是150。tranny估计贵一点,因为用的油多2qt。
不过这个换起来很简单,只要螺丝能顺利拧开,呵呵 |
|
d**********o 发帖数: 1321 | 2 简化数据
261个test文件:
完全正确的测试文件117个,占44.8%;
完全没做的测试文件 19个,占 7.3%;
其余半对的不对的,我自己也没时间去数
就让同专业的小伙伴们帮忙来数、来作鉴定、指导我吧。
compiler框架搭起来,多少也该给些分的吧~~
我不认为难,但我真的是没有足够的时间,实在是写不完这牛毛一样多的测试~~ *_^
上一贴最后总结部分重贴如下(不同专业的读者可以完全忽略上一贴):
a00 (Output OK) a00 (Output OK)
a001 (Output OK) a001 (Output OK)
a002 (Output OK) a002 (Output OK)
a009 (Output OK) a009 (Output OK)
a01 (Output OK) ... 阅读全帖 |
|
d**********o 发帖数: 1321 | 3 简化数据
261个test文件:
完全正确的测试文件117个,占44.8%;
完全没做的测试文件 19个,占 7.3%;
其余半对的不对的,我自己也没时间去数
就让同专业的小伙伴们帮忙来数、来作鉴定、指导我吧。
compiler框架搭起来,多少也该给些分的吧~~
我不认为难,但我真的是没有足够的时间,实在是写不完这牛毛一样多的测试~~ *_^
上一贴最后总结部分重贴如下(不同专业的读者可以完全忽略上一贴):
a00 (Output OK) a00 (Output OK)
a001 (Output OK) a001 (Output OK)
a002 (Output OK) a002 (Output OK)
a009 (Output OK) a009 (Output OK)
a01 (Output OK) ... 阅读全帖 |
|
d**********o 发帖数: 1321 | 4 最终版本的compiler测试结果
=================================================
Output of Building User Code
Explode the tar
c-.l
c-.y
scanType.h
makefile
symtab.h
symtab.cpp
emitCode.h
emitCode.cpp
20131214164956-huang-CS445-F13-A5.tar: POSIX tar archive (GNU)
Tests: directory
c-.l: lex description text
c-.y: lex description text
emitCode.cpp: ASCII C++ program text
emitCode.h: ... 阅读全帖 |
|
d**********o 发帖数: 1321 | 5 最终版本的compiler测试结果
=================================================
Output of Building User Code
Explode the tar
c-.l
c-.y
scanType.h
makefile
symtab.h
symtab.cpp
emitCode.h
emitCode.cpp
20131214164956-huang-CS445-F13-A5.tar: POSIX tar archive (GNU)
Tests: directory
c-.l: lex description text
c-.y: lex description text
emitCode.cpp: ASCII C++ program text
emitCode.h: ... 阅读全帖 |
|
z*********n 发帖数: 1451 | 6
也放松一下,贴个以前写的编译时间计算int to Roman number的C++ metaprogramming
, 学生时在实验室天天就玩这种东西了:
class R2I {
const static int DIG;
public:
constexpr static char IN[] = "MCDXLVI"; ///This is the INPUT number;
const static int OUT;
};
template struct ID {};
template <> struct ID <'I'> { static const int I = 0; static const int V = 1
; };
template <> struct ID <'V'> { static const int I = 1; static const int V = 5
; };
template <> struct ID <'X'> { static const int I = 2; static const int V =
10... 阅读全帖 |
|
c*****n 发帖数: 96 | 7 来自主题: JobHunting版 - 上一道题吧 int getLongestBrackets(char *str, int *num){
char *p = str;
int diff = 0;
int maxLen = 0;
int curLen = 0;
while (*p){
while (*p && *p == ')') p++;
while (*p && diff >= 0){
if (*p == '(') diff ++;
if (*p == ')') diff --;
curLen++;
}
if (*p || diff <= 0){
curLen += diff;
if (curLen > maxLen){
maxLen = curLen;
*num = 0;
} else if(curLen == m... 阅读全帖 |
|
c*********r 发帖数: 19468 | 8 你对Torsen的工作原理完全想偏了……套用你的摩擦力理论来分析open diff的话
spider gear对两个side gear也有向两侧推的力(图我就不贴了,想必大家对bevel
gear open diff的构造都很熟悉了),按你的理论,转弯时side gear和diff case之间
会有滑动摩擦,于是所有的open diff都等同于clutch type LSD……
这么说吧,你说的这种摩擦力有没有?有,所以现实中的open diff都不是象理论上那
样locking factor为0,然而,这根本就是一个副产物……
Torsen也一样,所以在下图你可以看到side gear和diff case之间和通常的open diff
一样有一个避免直接接触、降低摩擦力用的thrust washer
Torsen A的工作原理其实我前面已经讲到了,再说得明白点:
1)直线常态是diff case通过worm wheel带动worm gear转,两侧worm gear得到的扭矩
相同,类比于open diff
2)一侧traction下降,则该侧车轮出现超速趋势,worm gear试... 阅读全帖 |
|
x********3 发帖数: 160 | 9 第二题我想是可以用greedy的。我基本的思路是首尾两项肯定是在选的elements中的。
初始化是选择的序列是0,1,2..k-2,n-1(从0开始计)。循环从倒数第二项开始决定他
应该所在的index的位置,直到正数第二项为止。中间的调整的过程有点复杂,可能可
以简化。下面是我随便写的代码。写得蛮差的,欢迎大家测试指正。
$k = 4;
$a = Array(1, 2, 5, 6, 11, 16, 17);
$records = Array();
for ($i = 1; $i < $k - 1; $i++)
{
$record = new Record($a[$i] - $a[$i - 1], $i);
$records[$i - 1] = $record;
}
$records[$k - 2] = new Record($a[count($a) - 1] - $a[$k - 2], count($a) - 1);
for ($last = $k - 2; $last > 0; $last--)
{
for ($i = $records[$la... 阅读全帖 |
|
h********r 发帖数: 51 | 10 下面这个方法行不行? O(n), 模拟一次买卖的DP解法。大牛们看看对不对?
#include
#include
#include
void dump(int *x, int l) {
int i;
for (i = 0; i < l; ++ i) {
printf("%d ", x[i]);
}
printf("\n");
}
int main() {
int array[] = {3, 6, 8, 4, 5, 7, 9, 13, 15, 10, 6, 2, 7, 11, 8, 6};
int len = sizeof(array)/sizeof(int);
assert (len >= 4);
int *a = (int*)malloc(sizeof(int)*len);
int *b = (int*)malloc(sizeof(int)*len);
int *c = (int*)malloc(sizeof(... 阅读全帖 |
|
e**n 发帖数: 5876 | 11 multi plate clutch, 据说是新版forester的plate的数量增加了, 所以torque能更多
得往后传. rear differential case的体积增大, 应该是为了handle更大的torque.
如果forester以前vLSD+VDC, 那现在算缩水, 但原来没有VDC, vLSD和VDC比, 谁强还不
好说. 不少人认为VDC比以前的vLSD强
"I tested this scenario on massive slab of 4 inch thick ice. I drive a 08
wrx MT with open front and rear diffs. I had mom and sister video the car
from both right and left sides getting on film front rear and right to left.
I turned lame mode(the TC button) off. This turns off TC exclusivley but
allows... 阅读全帖 |
|
w*********u 发帖数: 7 | 12 比如把人分成三组,A组什么都不吃,B组吃减肥药1,C组吃减肥药2,药效2略大于1,
很可能就会得到A和B没有sig diff,B和C没有sig diff但是A和C有sig diff。
就像上面有人说的,A和B(B和C)没有sig diff是power不够,如果sample size增大或
者两者之间的区别增大,都会增大power,从而得到sig diff。
假如你的结果真的是A和B没有sig diff,B和C没有sig diff,而A和C有sig diff,那么
用ANOVA,总的那个p value一般来说一定是sig。
ANOVA本身并非multi test,它只有一个test,就是test A B C三者之间到底有没有
diff。只有在ANOVA的基础上做两两对比的时候才是multi test。 |
|
c***x 发帖数: 628 | 13 According to these patent articles, pre-load has no direct impact what so
ever on the locking factor, as it is actuated by the ramp angles and clutch
clamping capacities.
The maximum difference between the output torques on either side of the diff
, at any instantaneous moment, can obviously be expressed as a torque. For a
clutch pack LSD, this torque typically expressed as a percentage of the
input torque to the differential, as the more input torque a clutch pack
diff receives (due to the fixe... 阅读全帖 |
|
k****n 发帖数: 369 | 14 code:
int testOneWay(int b[], int size, int start, int step, int w[], int diff);
int longest01(int b[], int n) {
int n0=0, n1=0;
count(b, n, &n0, &n1);
if (n0==n1) return n;
int w[2];
w[0]=1, w[1]=-1, more=0;
if (n0
int l1 = testOneWay(b, n, 0, 1, w, abs(n0-n1));
if (l1 == 2*MIN(n0,n1)) return l1;
l1 = testOneWay(b, n, n-1, -1, w, abs(n0-n1));
if (l1 == 2*MIN(n0,n1)) return l1;
int lc=0, rc=n-1;
int diff = abs(n0-n1);
while (b[lc+1] != m... 阅读全帖 |
|
J**9 发帖数: 835 | 15 Right, Not stable. So the last number can be any of 0..N-1:
example1:
=========
Original Array: 1, 2, 3, 4, 5,
Random 2: [3]=4 [4]=5 Diff=1
New Array: 1, 2, 3, 1,
Random 2: [1]=2 [3]=1 Diff=1
New Array: 1, 1, 3,
Random 2: [0]=1 [1]=1 Diff=0
New Array: 0, 3,
Random 2: [1]=3 [0]=0 Diff=3
New Array: 3,
Number left=3
example2:
==========
Original Array: 1, 2, 3, 4, 5,
Random 2: [3]=4 [1]=2 Diff=2
New Array: 1, 2, 3, 5,
Random 2: [2]=3 [3]=5 Diff=2
New Array: 1, 2, 2,
Random 2: [2]=2 [0]=1 Diff=1
New... 阅读全帖 |
|
y****n 发帖数: 743 | 16 1. 因为对称,计算1/8圆,就可以画整个圆。
2. 设d=x^2+y^2-r^2,当d>0,说明点在圆外
3. 最开始x=r,y=0
4. 下一个点,y++:
因为公式:(y+1)^2=y^2+2y+1,所以d+=2y+1。
如果d>0,则x--,同时d-=2x-1;
5. 重复第四步,直到1/8圆
public void DrawCircle(Bitmap bitmap, int centerX, int centerY, int r)
{
int x = r;
int y = 0;
int diff = 0;
while (x >= y)
{
DrawPixel(bitmap, centerX + x, centerY + y);
DrawPixel(bitmap, centerX - x, centerY + y);
DrawPixel(bitmap, centerX + x, centerY - y);
DrawPixel(bitmap, centerX - x, centerY - y);
DrawPixel(bitmap, centerX + y, centerY + x... 阅读全帖 |
|
t****t 发帖数: 387 | 17 抛砖引玉
第一个问题,假设有个thread pool来处理请求,假设每次用户请求包含id,
timestamp
在服务器端用一个数据结构来保存请求次数 map
class RequestHistory
{
int maxRequest = 10;
queue historyQueue;
bool isBlocked;
void HandlerRequest(datetime ts)
{
if(!isBlocked)
{
//check ts diff with oldest element ts
//4 possible cases, handle each case, should be easy
//queue size < 10, ts diff < 1min
//queue size < 10, ts diff > 1min
//queue size = 10, ts diff < 1min
//queue size = 10, ts diff > 1min
... 阅读全帖 |
|
r****t 发帖数: 10904 | 18 git 内置了一些关于 latex 的知识,加了 gitattributes 以后,diff 的时候应该会
在 hunk header 里面告诉改动发生在哪个 section, 不过我没有验证。 这个是 man
gitattributes, 里面还建议 *.bib diff=bibtex
Each group of changes (called a "hunk") in the textual diff output is
prefixed with a line of the form:
@@ -k,l +n,m @@ TEXT
This is called a hunk header. The "TEXT" portion is by default a
line that begins with an alphabet, an underscore or
a dollar sign; this matches what GNU diff -p output uses. This
default sel... 阅读全帖 |
|
c*********r 发帖数: 19468 | 19 我在149楼貌似根本没有谈及你说的问题1……不过我现在可以回答你:
引擎传来的扭矩必然是经过diff case传给worm gear
diff case传给worm gear的主要途径是worm wheel作用在worm gear上的切向力,另外
就是worm wheel作用给worm gear的轴向力导致的worm gear和diff case之间的摩擦力
。直道下worm gear和diff case没有相对运动趋势,所以后一个渠道实际上为0。一旦
一侧traction下降,或者在弯道,后一个渠道才会启用。
所以说,以动力的角度,永远都是worm wheel驱动worm gear,但请注意,这里不是说
worm wheel靠转动驱动worm gear的意思,而是说它是diff
case把引擎动力传递给worm gear的媒介。希望我这么说歧义能消除了……
补充一句,worm wheel转动的话,worm gear是相对于diff case转
worm wheel不转,worm gear相对diff case也不转,这和open diff类似
这个意义上,worm wheel很难驱动... 阅读全帖 |
|
b**********r 发帖数: 91 | 20 Run the ultimate example around 400 ms
here is my code
4, 13, 5, 4, 13, 6, 8, 12, 16, 9, 13, 13, 13, 16, 9, 2, 6, 5,
0, 4, 17, 22, 26, 39, 45, 53, 65, 81, 90, 103, 116, 129, 145, 154, 156,
162, 167,
4, 17, 22, 26, 39, 45, 53, 65, 81, 90, 103, 116, 129, 145, 154, 156,
162, 167, 13, 18, 22, 35, 41, 49, 61, 77, 86, 99, 112, 125, 141, 150,
152, 158, 163, 5, 9, 22, 28, 36, 48, 64, 73, 86, 99, 112, 128, 137, 139,
145, 150, 4, 17, 23, 31, 43, 59, 68, 81, 94, 107, 123, 132, 134, 140,
145, 13, 19, 27, 39... 阅读全帖 |
|
b**********r 发帖数: 91 | 21 Run the ultimate example around 400 ms
here is my code
4, 13, 5, 4, 13, 6, 8, 12, 16, 9, 13, 13, 13, 16, 9, 2, 6, 5,
0, 4, 17, 22, 26, 39, 45, 53, 65, 81, 90, 103, 116, 129, 145, 154, 156,
162, 167,
4, 17, 22, 26, 39, 45, 53, 65, 81, 90, 103, 116, 129, 145, 154, 156,
162, 167, 13, 18, 22, 35, 41, 49, 61, 77, 86, 99, 112, 125, 141, 150,
152, 158, 163, 5, 9, 22, 28, 36, 48, 64, 73, 86, 99, 112, 128, 137, 139,
145, 150, 4, 17, 23, 31, 43, 59, 68, 81, 94, 107, 123, 132, 134, 140,
145, 13, 19, 27, 39... 阅读全帖 |
|
l****c 发帖数: 838 | 22 You should read in the string and parse.
You don't know how long the first part string is or how long the number is.
So if you define:
char tempprice[10];
char ticker[10];
You have the risk of buffer overflow.
Here is my solution. I debug it as I wrote it, so it is not optimized.
it is pure C. You can get result with 2 lines of perl or python code
============================
#include
#include
#include
int main()
{
char *str = "GOOD|89.34";
char *ptoken, *... 阅读全帖 |
|
j********g 发帖数: 80 | 23 large judge过了
class Solution {
public:
int maxProfit(vector &prices) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(prices.size()<=1)
return 0;
vector diff;
for(int i=0;i
{
diff.push_back(prices[i+1]-prices[i]);
}
int posi =0;
int nega =0;
vector inter;
for(int j=0;j
{
... 阅读全帖 |
|
j********g 发帖数: 80 | 24 large judge过了
class Solution {
public:
int maxProfit(vector &prices) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(prices.size()<=1)
return 0;
vector diff;
for(int i=0;i
{
diff.push_back(prices[i+1]-prices[i]);
}
int posi =0;
int nega =0;
vector inter;
for(int j=0;j
{
... 阅读全帖 |
|
U***A 发帖数: 849 | 25 假定排序由小到大。
vector findABC(vector &v, int c){
int size = (int)v.size();
vector result;
int start=0;
int diff=0;
for(int i=1; i
diff += v[i]- v[i-1];
while (diff>c){
while(diff>c && start
diff = diff -(v[start+1]-v[start]);
start ++;
}
}
if(diff == c){
result.push_back(v[start]);
result.push_back(v[i]);
break;
}
}
... 阅读全帖 |
|
y*****e 发帖数: 712 | 26 他的意思是一旦碰到两个不同的,就把可能的三种情况,ins_a (a has extra letter),
ins_b(b has extra letter), replace都turn on, diff表示至少有一个不同的,这
时也turn on. 如果一直跑到最后所有的letter都相同,diff就remain as false, 也
return false.
一旦碰到两个不一样的,就要一直比较currA, currB, preA, preB, 如果preA !=
currB, 但insertionB是true, 说明insert extra letter to B是不可能的,就turn
off ins_B.同理其他的判断。
跑到最后总结,看A还是B还剩一个letter, 或者两者都跑到头了,再做判断。
我把这个超级genius的答案改写成java的了。。。。
public class FileCompare {
public boolean isDistanceZeroOrOne(IntFileIterator a,
IntFileIterator b) {
... 阅读全帖 |
|
t**********3 发帖数: 12623 | 27 因为Cayanne是Touareg平台,所以和Touareg一样,第一代Cayanne是center diff lock
标配,通过Advanced Offroad Tech Pkg可以配到Touareg V8和TDI V10的配置就是全手
动center diff lock+rear diff lock
这一代的Cayanne base和Cayanne S是多片耦合配auto-lock limited slip diff,可以
选配off-road tech pkg包括手动center diff lock和auto-lock rear diff |
|
w**********4 发帖数: 157 | 28 总是过不了Large Judge。
各位大侠有更好的解法吗?
public class Solution {
public int maxProfit(int[] prices) {
if (prices == null || prices.length == 0)
return 0;
int max =0;
for (int i = 0;i
int value = maxProfit(prices,i);
max = Math.max(value, max);
}
return max;
}
private int maxProfit(int[] prices, int index){
int maxfront =0;
int min =0;
int maxend =0;
for (int i=0;i<=index;i++){
if (prices[i]阅读全帖 |
|
w**********4 发帖数: 157 | 29 总是过不了Large Judge。
各位大侠有更好的解法吗?
public class Solution {
public int maxProfit(int[] prices) {
if (prices == null || prices.length == 0)
return 0;
int max =0;
for (int i = 0;i
int value = maxProfit(prices,i);
max = Math.max(value, max);
}
return max;
}
private int maxProfit(int[] prices, int index){
int maxfront =0;
int min =0;
int maxend =0;
for (int i=0;i<=index;i++){
if (prices[i]阅读全帖 |
|
y****n 发帖数: 743 | 30 改编成整数开方。算法复杂度说不清楚,远好于O(lgN)。
我只假设是O(lg(lgN))。
static Int64 SqrtInt(Int64 num)
{
Int64 maxRoot = (Int64)1 << 31;
Int64 root = 1;
Int64 oldDiff = Int64.MaxValue;
Int64 diff = num - root * root;
int loop = 0;
while ((loop < 2) || (Math.Abs((double)diff) < Math.Abs((double)oldDiff)
))
{
root = Math.Min(maxRoot, root + diff / root / 2);
oldDiff = diff;
diff = num - root * root;
loop++;
}
return (diff < 0) ? root - 1 : root;
} |
|
d****n 发帖数: 233 | 31 I'm wondering if the following works.
long maxSumNonOverlap(Record[] records) {
long[] sums = new long[records.length + 1];
long max = 0;
sums[0] = 0;
Arrays.sort(records, new Comparator() {
@Override
public int compare(Record o1, Record o2) {
int diff = o1.end - o2.end;
return diff == 0? o1.start - o2.start : diff;
}});
int i = 0;
for(; i < reco... 阅读全帖 |
|
d****n 发帖数: 233 | 32 I'm wondering if the following works.
long maxSumNonOverlap(Record[] records) {
long[] sums = new long[records.length + 1];
long max = 0;
sums[0] = 0;
Arrays.sort(records, new Comparator() {
@Override
public int compare(Record o1, Record o2) {
int diff = o1.end - o2.end;
return diff == 0? o1.start - o2.start : diff;
}});
int i = 0;
for(; i < reco... 阅读全帖 |
|
w********s 发帖数: 1570 | 33 text justification和dp有毛关系。
class Solution {
public:
string reorder(string& s, int L, int nWords)
{
int diff = L - s.length();
if (nWords == 1)
{
string r = s;
for (int i = 0; i < diff; ++i) r += ' ';
return r;
}
int each = diff / (nWords - 1);
int extra = diff % (nWords - 1);
string r;
int l = s.length();
for (int i = 0; i < l; ++i)
{
... 阅读全帖 |
|
C****t 发帖数: 53 | 34 一个hashtable就好, key为元素,value为两个数【重复次数,visited的状态】
def total(nums, tar):
maps = {}
res = 0
for ele in nums:
if ele not in maps:
maps[ele] = [1,0]
else:
maps[ele][0] += 1
for ele in nums:
if maps[ele][1] = 1: continue
diff = tar - ele
if diff not in maps: continue
rep1, rep2 = maps[ele][0], maps[diff][0]
if ele == diff and rep1 > 1:
res += rep1*(rep1-1)//2
elif ele != diff:
... 阅读全帖 |
|
v*******n 发帖数: 8995 | 35 今天趁lbj撸三双,太能撸心情好,我就把espn专家的意见在打乒乓球的时候跟他说了。
没想到他年鱼嘴一撅,说,屁,尽扯蛋,天天盯着这些鸡毛蒜皮的猥不猥琐, 我告诉
你,lbj就是今年防守第二好的sf,仅次于马刺卡哇伊,高阶数据,你会看吗?说着,
立刻发过来一推数据,唉,职业的就是不一样。
我接着说,那还是不如马刺那个面瘫,不是吗?
太能撸长叹一声,你看马刺以邓肯为首那一推护框的,我这个队伍里,他妈的有谁啊?
LeBron
8.3 DFGA, 37.5 DFG% for a -7.3 FG diff%, #1 for Forwards
3pt DFGA: 1/3.2 (31.3%, -3.4 diff%)
2pt DFGA: 2.1/5.1 (41.2%, -7.7 diff%)
DBPM: 2.1 #3 for SFs
DRPM: 2.45 #2 for SFs
D Win Shares: 3.6 #3 for SFs (team related)
Kawhi
9.4 DFGA 39.4 DFG% -5.3 diff% #4 for Forwards
3pt:1/2.8 (34.8%,... 阅读全帖 |
|
c*********r 发帖数: 19468 | 36 if you ask me to classify them, I'll do it this way:
1. AWD w/center diff
1.1 AWD w/open center diff
1.1.1 AWD w/bevel-gear open center diff
power split ratio (normal): 50:50
limited slip mechanism: ABS (if any)
examples: many SUVs w/o center diff lock
1.1.2 AWD w/planetary-gear open center diff
power split ratio (normal): fixed & biasing towards one side, usually the
rear wheels
limited slip mechanism: ABS (if any)
example: E550 4Matic
1.2 AWD w/lockable center diff (but no limited slip mechani |
|
发帖数: 1 | 37 【 以下文字转载自 BetterStock 俱乐部 】
发信人: drugbull (药牛), 信区: BetterStock
标 题: VolumeWeighted-MACD的公式,编程,及应用,代替常规MACD
发信站: BBS 未名空间站 (Sun Jun 17 18:36:30 2018, 美东)
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
def fastAvg = sum(data = (close * volume), length = fastLength)/sum(data = v
olume, length = fastLength);
def slowAvg = sum(data = (close * volume), length = slowLength)/sum(data = v
olume, length = slowLength);
plot Value = fastAvg - slowAvg;
plot Avg = ExpAver... 阅读全帖 |
|
e**n 发帖数: 1326 | 38 Both have open diff on the front.
Subaru has electrically controlled full-time center diff.
Audi has mechanical torsen center diff, full time also.
Subaru has a viscous limited slip diff at the rear.
I believe audi has a open diff at the rear.
So subaru is slightly better, especially in snowy conditions with ESP off.
But, i don't think vast majority of people can really tell the difference
when driving. Both AWD are really good enough. Focus on other aspects of the
two if you want to choose betw... 阅读全帖 |
|
f*******t 发帖数: 7549 | 39 牛顿迭代法,任取一a,然后不断a = (a + n/a)/2循环,直到某个精度。
double sqrt(int n)
{
if(n <= 0)
return 0;
double ans = (double)n / 2.0;
int round = 0;
const double epsilon = 0.00001;
while(true) {
round++;
ans = (ans + (double)n / ans) / 2;
double diff = ans * ans - (double)n;
if(diff < 0)
diff = -diff;
if(diff < epsilon)
break;
}
printf("Calculated %d rounds\n", round);
return ans;
} |
|
f*******t 发帖数: 7549 | 40 练习时写的,开方数支持小数和负数
double sqrt(double n)
{
if(n <= 0.0)
return 0.0;
double ans = n / 2.0;
int round = 0;
const double epsilon = 0.00001;
while(true) {
round++;
ans = (ans + n / ans) / 2;
double diff = ans * ans - n;
if(diff < 0)
diff = -diff;
if(diff < epsilon)
break;
}
//printf("Calculated %d rounds\n", round);
return ans;
}
double powerDouble(double a, double n) {
bool neg = fa... 阅读全帖 |
|
A**u 发帖数: 2458 | 41 可惜啊...
1. 静下来,从2,3,4,5,试试,就找出规律啦
2. 动态规划问题.
找最大和Max-gain(1,n),等价于找“比对手最多赢多少”max-diff(1,n) +
max-diff(i,j) 为
1, A[i] - max-diff(i+1,j)
2, A[j] - max=diff(i,j-1)
的两个最大值
边界--- max-diff(i,i) = A[i] only one left, and it's A's turn.
用DP...反着做,O(N^2)
大牛。。太可惜了... |
|
d**********x 发帖数: 4083 | 42 应该没问题,和coldknight的程序在2-10000之内做了对比,结果完全一致。他的
nMaxStep我设置为了2 * target,不知道会不会引起问题。
在纸面上也做了不太严格的证明。。这样复杂度就是O(logn)。
对比程序:(前半部分还是coldknight的)
#include
#include
#include
using namespace std;
vector getJumpSteps(int nCur, int nMaxStep)
{
vector vec;
if (nCur <= 0 || nMaxStep < nCur)
return vec;
int flg = 1;
while (nCur + flg <= nMaxStep)
{
vec.push_back(nCur + flg);
flg = (flg << 1);
}
flg = 1;
while (nCur - ... 阅读全帖 |
|
y****n 发帖数: 743 | 43 牛顿迭代的算法要远好于Binary Search的O(lgn)。
贴个Sqrt(double)的算法。
static double Sqrt(double num)
{
double root = 1;
double diff = num - root * root;
double oldDiff = double.MaxValue;
int loop = 0;
while ((loop < 2) || (Math.Abs(diff) < Math.Abs(oldDiff)))
{
root = root + diff / root / 2;
oldDiff = diff;
diff = num - root * root;
loop++;
}
return root;
} |
|
d*****a 发帖数: 3 | 44 贴一下我的代码,为了测试方便,我用的是char*代替的iterator,只要不往回走,意思
应该是一样的。大牛帮忙看看有没有什么问题
bool isDistanceZeroOrOne(const char *a, const char *b)
{
bool insertA = false;
bool insertB = false;
bool replace = false;
bool diff = false;
char preA;
char preB;
while (*a != '\0' && *b != '\0')
{
if (!insertA && !insertB && !replace)
{
if (*a != *b)
{
insertA = true;
insertB = true;
replace = true;
... 阅读全帖 |
|
S*******C 发帖数: 822 | 45 下面答案能过所有test case,如果谁发现有错请告诉我
public boolean isDistanceZeroOrOne(IntFileIterator a, IntFileIterator b)
{
boolean ins_a = false, ins_b = false, replace = false, diff = false;
int pre_a = 0, pre_b = 0;
while (a.hasNext() && b.hasNext()) {
int cur_a = a.next(), cur_b = b.next();
if (!ins_a && !ins_b && !replace) {
if (cur_a != cur_b) {
ins_a = ins_b = replace = diff = true;
}
} else {... 阅读全帖 |
|
z***y 发帖数: 7151 | 46 Now I have a VLDB about 2.5 Tera bytes. Now I need to do full backup right
away, but also find that the log backup job is running. So in that case can
I go ahead doing full backup while the log backup is running?
这个是为一家软件公司的Principle Field Engineer面试的。 属于那种比较不常见的
问题。
还有一道关于备份的。
You as DBA need to do full backup for your production database, but you were
told the backup plan for this database is FULL==》DIFF==>DIFF==>FULL==>DIFF
==>DIFF==>DIFF from Sunday to Saturday. You were also told to keep t |
|
k********e 发帖数: 702 | 47 要这么简单的话,我也不会这么猴急在这里问了。
backup原理我都知道
我也知道必须这么顺序
问题是: 没这个条件!
现在的条件是:
1.
1个月前的fullbackup (被覆盖,没有了!)
2.
随后的diff backup都有
3.
随后的weekly fullbackup (没完成,都是partial 文件,所以checkpoint LSN没变,还
是在一个月前的fullbackup,所以diff backup的起始位置没变)
现在可以预见的解决办法是:
拿这个partial 文件,生成MDF,用diff backup apply map 所有的change上去,
有办法生成尽量多的数据么?
理论上,大量的diff数据都在diff backup里面,也就是最近的变化数据,是最需要恢
复的部分。
. |
|
S**********r 发帖数: 28 | 48 小女子打算求一个ODE的特征值:
(d^4/dt^4) y(t)=lambda* y(t),t in [0,1]
边值条件是y'(0)=y'(1)=y''(0)=y''(1)=0
据说有个很神奇的软件叫chebfun()可以做,小女子于是编了下面这个code
trunc=30;
tic
L = chebop(@(x,u) diff(u,4), [0,1]);
L.lbc = @(u) diff(u,1);
L.lbc =@(u) diff(u,2);
L.rbc = @(u) diff(u,1);
L.rbc =@(u) diff(u,2);
[V,D] = eigs(L,trunc);
disp(diag(D)), toc
可是有报错说
Error using eig
Matrix must be square.
各位计算数学大侠请帮忙看看小女子哪里错了?谢谢! |
|
R*******T 发帖数: 1171 | 49 小女子打算求一个ODE的特征值:
(d^4/dt^4) y(t)=lambda* y(t),t in [0,1]
边值条件是y'(0)=y'(1)=y''(0)=y''(1)=0
据说有个很神奇的软件叫chebfun()可以做,小女子于是编了下面这个code
trunc=30;
tic
L = chebop(@(x,u) diff(u,4), [0,1]);
L.lbc = @(u)[ diff(u,1), diff(u,2)];
L.rbc = @(u)[ diff(u,1), diff(u,2)]
[V,D] = eigs(L,trunc);
disp(diag(D)), toc
试试这个,不知道对不对。 |
|
y******g 发帖数: 317 | 50 eg, 一个correlational study想知道,身高和体重的关联程度
把一群人的身高体重一一对应起来。
ind diff就在一一对应这个过程中被控制了。所以,就算身高1。7的人和1。3的人也可
以放在一起。
最后的结果,展示的是身高体重的关系。
另一个意义上的ind diff,就是某些人身高体重的比例明显跟平均水平不一样。那么,如
果这些ind diff过大,群体的身高体重关系就会不显著。
总之我还是认为,correlation 不是以研究ind diff为目的的。而是要找出被ind diff
掩盖下的群体指标。
还望指正。。。 |
|