Question:
Find the smallest k elements
Answer:
void findkmin(int *array, int len, int k) {
int* kmin = new int[k];
if (len <= k) {
for (int i = 0; i < len; i++)
kmin[i] = array[i];
}
else {
for (int i = 0; i < len; i++) {
int j;
for (j = 0; j < ((i < k) ? i : k); j++) {
if (kmin[j] > array[i])
break;
}
if (j < k) {
for (int m = k-1; m > j; m--)
kmin[m] = kmin[m-1];
kmin[j] = array[i];
}
}
}
for (int i = 0; i < k; i++)
cout << kmin[i] << " ";
cout << endl;
delete [] kmin;
}
Largest subarray max sum problem
Question:
Write an efficient C program to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.
some numbers are negative.
Time Complexity: O(n)
Write an efficient C program to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.
some numbers are negative.
Time Complexity: O(n)
Answer:
void maxsumofsubarray(int* array, int len) {
int curMax = 0;
int mi = -1;
int mj = -1;
int max;
bool max_init = false;
for (int i = 0; i < len; i++) {
if (curMax <= 0) {
curMax = array[i];
mi = i;
mj = i;
} else {
curMax += array[i];
}
if (!max_init || max < curMax) {
max = curMax;
mj = i;
max_init = true;
}
}
for (int i = mi; i <= mj; i++) {
cout << array[i] << " ";
}
cout << endl;
cout << " max sub array sum is " << max << endl;
}
void maxsumofsubarray(int* array, int len) {
int curMax = 0;
int mi = -1;
int mj = -1;
int max;
bool max_init = false;
for (int i = 0; i < len; i++) {
if (curMax <= 0) {
curMax = array[i];
mi = i;
mj = i;
} else {
curMax += array[i];
}
if (!max_init || max < curMax) {
max = curMax;
mj = i;
max_init = true;
}
}
for (int i = mi; i <= mj; i++) {
cout << array[i] << " ";
}
cout << endl;
cout << " max sub array sum is " << max << endl;
}
Jesus's mother and brethren
耶稣的母亲和弟兄
耶稣的母亲和他弟兄来了,因为人多,不得到他跟前。 有人告诉他说:“你母亲和你弟兄站在外边,要见你。” 耶稣回答说:“听了神之道而遵行的人就是我的母亲,我的弟兄了。” (路加福音 8:19-21 和合本)
Then came to him his mother and his brethren, and could not come at him for the press.And it was told him by certain which said, Thy mother and thy brethren stand without, desiring to see thee.And he answered and said unto them, My mother and my brethren are these which hear the word of God, and do it. (Luke 8:19-21 KJV)
耶稣的母亲和弟兄来找耶稣,可是因为人太多,到不了耶稣的跟前。 “有人告诉祂说:‘你母亲和你弟兄站在外边,要见你。’”按照一般人的观念,听说母亲和兄弟来了,应该停下讲道,赶快前往迎接。然而出于人意料的是,“他却回答那人说:‘谁是我的母亲?谁是我的弟兄?’就伸手指着门徒,说:‘看哪,我的母亲,我的弟兄。凡遵行我天父旨意的人,就是我的弟兄姐妹和母亲了。’”(太 12:48-50 ) 即祂的母亲和弟兄是听了神的道而遵行的人。那些接近耶稣的人,乃是那些认真负起他们向着神的职责之人。这并不意味着家庭的维系是不重要的、或可忽略的,耶稣不是在否认祂的家庭,甚至当祂为了完成救赎世人的工作而被挂在十字架上时,祂在痛苦中仍然想到祂的母亲(约十九26-27)。祂的意思是:我们对神的职责必须优于其他一切。
耶稣的母亲和他弟兄来了,因为人多,不得到他跟前。 有人告诉他说:“你母亲和你弟兄站在外边,要见你。” 耶稣回答说:“听了神之道而遵行的人就是我的母亲,我的弟兄了。” (路加福音 8:19-21 和合本)
Then came to him his mother and his brethren, and could not come at him for the press.And it was told him by certain which said, Thy mother and thy brethren stand without, desiring to see thee.And he answered and said unto them, My mother and my brethren are these which hear the word of God, and do it. (Luke 8:19-21 KJV)
耶稣的母亲和弟兄来找耶稣,可是因为人太多,到不了耶稣的跟前。 “有人告诉祂说:‘你母亲和你弟兄站在外边,要见你。’”按照一般人的观念,听说母亲和兄弟来了,应该停下讲道,赶快前往迎接。然而出于人意料的是,“他却回答那人说:‘谁是我的母亲?谁是我的弟兄?’就伸手指着门徒,说:‘看哪,我的母亲,我的弟兄。凡遵行我天父旨意的人,就是我的弟兄姐妹和母亲了。’”(太 12:48-50 ) 即祂的母亲和弟兄是听了神的道而遵行的人。那些接近耶稣的人,乃是那些认真负起他们向着神的职责之人。这并不意味着家庭的维系是不重要的、或可忽略的,耶稣不是在否认祂的家庭,甚至当祂为了完成救赎世人的工作而被挂在十字架上时,祂在痛苦中仍然想到祂的母亲(约十九26-27)。祂的意思是:我们对神的职责必须优于其他一切。
Transform the binary search tree into a sorted two-way linked list
Question:
Transform the binary search tree into a sorted two-way linked list.
do not use recursion.
do not create any new node, only adjust the pointer to point.
10
/ \
6 14
/ \ / \
4 8 12 16
-->>
4=6=8=10=12=14=16
struct BSTreeNode
{
int m_nValue; // value of node
BSTreeNode *m_pLeft; // left child of node
BSTreeNode *m_pRight; // right child of node
};
Answer:
inline BSTreeNode* eleminateMinNode(BSTreeNode** tree) {
BSTreeNode* treeHead = tree;
if (!treeHead)
return 0;
BSTreeNode treeHeadParent = 0;
while (treeHead->m_pLeft) {
treeHeadParent = treeHead;
treeHead = treeHead->m_pLeft;
}
if (treeHeadParent)
treeHeadParent->m_pLeft = treeHead->m_pRight;
if (treeHead == *tree)
*tree = treeHead->m_pRight;
return treeHead;
}
inline BSTreeNode* eleminateMaxNode(BSTreeNode** tree) {
BSTreeNode* treeHead = tree;
if (!treeHead)
return 0;
BSTreeNode treeHeadParent = 0;
while (treeHead->m_pRight) {
treeHeadParent = treeHead;
treeHead = treeHead->m_pRight;
}
if (treeHeadParent)
treeHeadParent->m_pRight = treeHead->m_pLeft;
if (treeHead == *tree)
*tree = treeHead->m_pLeft;
return treeHead;
}
void BSTreeToDoubleLinkChainInternal(BSTreeNode* tree, BSTreeNode** headp, BSTreeNode** tailp) {
if (!tree)
return;
BSTreeNode* tail = tree;
BSTreeNode* right = tail->m_pRight;
BSTreeNode* minRight = eleminateMinNode(&right);
while (minRight && minRight != tail) {
tail->m_pRight = minRight;
minRight->m_pLeft = tail;
tail = minRight;
minRight = eleminateMinNode(&right);
}
tail->m_pRight = 0;
BSTreeNode* left = tree->m_pLeft;
BSTreeNode* maxLeft = eleminateMaxNode(&left);
BSTreeNode* head = tree;
while (maxLeft && maxLeft != head) {
head->m_pLeft = maxLeft;
maxLeft->m_pRight = head;
head = maxLeft;
maxLeft = eleminateMaxNode(&left);
}
head->m_pLeft = 0;
*headp = head;
*tailp = tail;
}
Transform the binary search tree into a sorted two-way linked list.
do not use recursion.
do not create any new node, only adjust the pointer to point.
10
/ \
6 14
/ \ / \
4 8 12 16
-->>
4=6=8=10=12=14=16
struct BSTreeNode
{
int m_nValue; // value of node
BSTreeNode *m_pLeft; // left child of node
BSTreeNode *m_pRight; // right child of node
};
Answer:
inline BSTreeNode* eleminateMinNode(BSTreeNode** tree) {
BSTreeNode* treeHead = tree;
if (!treeHead)
return 0;
BSTreeNode treeHeadParent = 0;
while (treeHead->m_pLeft) {
treeHeadParent = treeHead;
treeHead = treeHead->m_pLeft;
}
if (treeHeadParent)
treeHeadParent->m_pLeft = treeHead->m_pRight;
if (treeHead == *tree)
*tree = treeHead->m_pRight;
return treeHead;
}
inline BSTreeNode* eleminateMaxNode(BSTreeNode** tree) {
BSTreeNode* treeHead = tree;
if (!treeHead)
return 0;
BSTreeNode treeHeadParent = 0;
while (treeHead->m_pRight) {
treeHeadParent = treeHead;
treeHead = treeHead->m_pRight;
}
if (treeHeadParent)
treeHeadParent->m_pRight = treeHead->m_pLeft;
if (treeHead == *tree)
*tree = treeHead->m_pLeft;
return treeHead;
}
void BSTreeToDoubleLinkChainInternal(BSTreeNode* tree, BSTreeNode** headp, BSTreeNode** tailp) {
if (!tree)
return;
BSTreeNode* tail = tree;
BSTreeNode* right = tail->m_pRight;
BSTreeNode* minRight = eleminateMinNode(&right);
while (minRight && minRight != tail) {
tail->m_pRight = minRight;
minRight->m_pLeft = tail;
tail = minRight;
minRight = eleminateMinNode(&right);
}
tail->m_pRight = 0;
BSTreeNode* left = tree->m_pLeft;
BSTreeNode* maxLeft = eleminateMaxNode(&left);
BSTreeNode* head = tree;
while (maxLeft && maxLeft != head) {
head->m_pLeft = maxLeft;
maxLeft->m_pRight = head;
head = maxLeft;
maxLeft = eleminateMaxNode(&left);
}
head->m_pLeft = 0;
*headp = head;
*tailp = tail;
}
Take heed therefore how ye hear
恩赐
所以,你们应当小心怎样听;因为凡有的,还要加给他;凡没有的,连他自以为有的,也要夺去。” (路加福音 8:18 和合本)
Take heed therefore how ye hear: for whosoever hath, to him shall be given; and whosoever hath not, from him shall be taken even that which he seemeth to have. (Luke 8:18 KJV)
这句话与撒种的比喻和交银的比喻(19:26)连在一起。正确的听是很重要的,不要像比喻中那不结果实的种子。“凡有的还要加给他”,也是在提醒我们同一个功课。这当然不是个鼓励有钱阶级的信息,它是与听神的道有关的。也就是说,当一个人,谦卑地领受主的教导,那么神就会把更多的真理赐给他,让他明白的更多,领受的更多。如果一个人,在神面前骄傲,他不仅没有办法领受到更多真理,甚至连自己已经明白的一些也会失去。这样的观念,也可以用在恩赐的使用上,如果我们认真使用神所赐的,就有添加,如果不用,甚至连我们自以为有的也会失去。
所以,你们应当小心怎样听;因为凡有的,还要加给他;凡没有的,连他自以为有的,也要夺去。” (路加福音 8:18 和合本)
Take heed therefore how ye hear: for whosoever hath, to him shall be given; and whosoever hath not, from him shall be taken even that which he seemeth to have. (Luke 8:18 KJV)
这句话与撒种的比喻和交银的比喻(19:26)连在一起。正确的听是很重要的,不要像比喻中那不结果实的种子。“凡有的还要加给他”,也是在提醒我们同一个功课。这当然不是个鼓励有钱阶级的信息,它是与听神的道有关的。也就是说,当一个人,谦卑地领受主的教导,那么神就会把更多的真理赐给他,让他明白的更多,领受的更多。如果一个人,在神面前骄傲,他不仅没有办法领受到更多真理,甚至连自己已经明白的一些也会失去。这样的观念,也可以用在恩赐的使用上,如果我们认真使用神所赐的,就有添加,如果不用,甚至连我们自以为有的也会失去。
Reset user password for your own Ghost blog
If you do not config mail up for your ghost blog,
it maybe a big problem once you lost your user password.
however, methods are always more than problems.
We can fix it up by reset it.
1. Find out your database name in your ghost config, it is maybe in config.production.json
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"user": "ghost-452",
"password": "dade1b0565f2585e07c7",
"database": "ghost_production_acm"
2. Use mysql to reset the password.
mysql -u root -p
Enter the password for root account.
mysql> use ghost_production_acm;
mysql> select * from users;
ghost use bcrypthash for the password.
You can get bcrypt hash string from http://bcrypthashgenerator.apphb.com/
mysql>update users set password='
it maybe a big problem once you lost your user password.
however, methods are always more than problems.
We can fix it up by reset it.
1. Find out your database name in your ghost config, it is maybe in config.production.json
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"user": "ghost-452",
"password": "dade1b0565f2585e07c7",
"database": "ghost_production_acm"
2. Use mysql to reset the password.
mysql -u root -p
Enter the password for root account.
mysql> use ghost_production_acm;
mysql> select * from users;
ghost use bcrypthash for the password.
You can get bcrypt hash string from http://bcrypthashgenerator.apphb.com/
mysql>update users set password='
$2b$10$PaL8tKcU4i0CsjRrM6BhROVQMwwLFw2HSx/kWlAUgja23fNllc2Fy' where email='your@email';
#Additionally : if the account has been locked,
#you can set status to active to unlock the account, like that:
#update users set status = “active”;
mysql>flush privileges;
mysql>quit
3.Restart your ghost blog and login again.
ghost stop
ghost start
config.production.json
Set up multi web server on a single VPS via ghost
First please refer to set up ghost on your VPS.
Set up ghost(a fully open source, hackable platform for building and running a modern online publication) on your google compute engine.
Set up ghost(a fully open source, hackable platform for building and running a modern online publication) on your google compute engine.
Subscribe to:
Posts (Atom)
fixed: embedded-redis: Unable to run on macOS Sonoma
Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...
-
F:\webrowser>react-native run-android Scanning folders for symlinks in F:\webrowser\node_modules (73ms) Starting JS server... Buildin...
-
Refer: https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain https://www.tensorflow.org/tutorials/image_recognition
-
Solution react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android...