先吐槽一下Google Doc。。还不如在collabedit上写呢。。拿word来coding伤不起。。
Hi, did you receive my phone call?
nope...
hmm, ok, please hold on for a moment
sure,
f(x) = ax^2 + bx +c
arr[] = {-6, 4, 6, 7, 9}
给定一个二次函数和一个升序数组,将这个升序数组根据f(x)的值重新排序该数组。
alpha = -1*(b/(2*a))
void process(double a,double alpha, int n){
if(a==0){
if(b>=0)
return;
reverse(arr,0,n)
return;
}
int k = 0;
while(k0)
reverse(arr,0,k);
else
reverse(arr,k,n);
int *tmp = new int[n];
int i = 0,j= k;
int cnt = 0;
while(i s;
double compute(int a,int b){
double res = 0;
int dec = 0;
while(1){
while(a::iterator it = s.find(str);
if(it!=s.end()){
//loop
return ...
}
s.insert(str);
a*=10;
dec++;
}
double t = a/b;
a = a%b;
res += t/10^dec;
}
}
void process(double a,double alpha, int n){
if(a==0){
if(b>=0)
return;
reverse(arr,0,n)
return;
}
int
k = 0;
while(k
k++;
if(a>0)
reverse(arr,0,k);
else
reverse(arr,k,n);
int
*tmp = new int[n];
int
i = 0,j= k;
int
cnt = 0;
while(i
if(f(arr[i])
tmp[cnt++]
= arr[i++];
}else
tmp[cnt++]
= arr[j++];
}
while(i
tmp[cnt++]
= arr[i++];
while(j
tmp[cnt++]
= arr[j++];
for(int
i=0;i
arr[i]
= tmp[i];
delete[]
tmp;
}
2.
5 / 3 = 1.66..
找循环节。
set s;
double compute(int a,int b){
double
res = 0;
int
dec = 0;
while(1){
while(a
string str = build(a,b);//a_b
set::iterator
it = s.find(str);
if(it!=s.end()){
//loop
return
...
}
s.insert(str);
a*=10;
dec++;
}
double t = a/b;
a = a%b;
res += t/10^dec;
}
}