The document defines a max function that returns the greater of two values of any type using templates. It starts with max functions for int and double, then defines a template version that can accept types like int and double. It also defines a Calc class to perform addition and multiplication, then modifies it using templates to allow different numeric types as parameters and return values.
The document discusses inheritance between classes in C++. It shows a Super class and a Sub class that inherits from Super. It demonstrates calling methods on instances of the subclasses and using references and pointers between the parent and child classes. It also shows proper use of virtual functions and destructors when inheriting.
The document defines two classes - Vault and Bank. Vault stores an amount of money. Bank stores a reference to a Vault instance, width, height, and has constructors to initialize these attributes. It also defines static methods to round down a double value and get/set the branch name. The main function demonstrates creating Bank instances with different parameters and calling methods on one Bank instance.
The document defines a base Shape class and derived Circle, Rect, and Triangle classes. The Shape class contains common properties like name, width, and height. It also contains a pure virtual getArea() method that each derived class implements differently based on the shape's area calculation formula. The main function creates instances of each shape class and calls printArea() to display the name and calculated area.
Viewpoints Research Institute is a nonprofit organization founded in 2001 that conducts research focused on powerful ideas education, computing technologies, and user interfaces to aid learning. The organization's research is influenced by constructivism and seeks to apply theories from thinkers like Piaget and Papert to develop new educational tools and content. Key areas of research include teaching and learning powerful ideas, representing knowledge, interfaces for learning, and inventing new computing technologies to advance education. The goal is to help learners develop fluency in thinking, math, and science through new human-computer environments.
This document discusses the rule of three/five in C++ and provides examples of deep copying for a Person class. It shows how to properly implement a copy constructor, copy assignment operator, and destructor to manage memory on the heap. Without following the rule of three/five, issues like shallow copying, dangling pointers, and memory leaks can occur when objects are copied or assigned.
The document discusses inheritance and polymorphism in C++. It shows examples of defining base and derived classes, and using virtual functions to allow polymorphic behavior. It also covers issues that can arise from multiple inheritance like ambiguous function calls, and ways to resolve them like using virtual inheritance or explicitly calling the base class function. Dynamic casting is demonstrated to check an object's type at runtime.
The document defines a Complex class to represent complex numbers with real and imaginary parts. It overloads operators like +, -, *, / to allow Complex objects to be added, subtracted, multiplied and divided. It also defines assignment operators +=, -=, *=, /= to perform operations like addition and assignment in one step. Finally, it defines a == operator to allow Complex objects to be compared for equality.
The document describes a SparseMatrix class that represents a sparse matrix using only non-zero elements, with methods to transpose, add, subtract, and multiply sparse matrices. It stores matrix elements as (row, column, value) tuples in a smArray, and the Transpose method returns a new SparseMatrix containing the transpose by iterating through each column and swapping the row and column for each non-zero element.
Continuous Control with Deep Reinforcement Learning, lillicrap et al, 2015Chris Ohk
油
The paper introduces Deep Deterministic Policy Gradient (DDPG), a model-free reinforcement learning algorithm for problems with continuous action spaces. DDPG combines actor-critic methods with experience replay and target networks similar to DQN. It uses a replay buffer to minimize correlations between samples and target networks to provide stable learning targets. The algorithm was able to solve challenging control problems with high-dimensional observation and action spaces, demonstrating the ability of deep reinforcement learning to handle complex, continuous control tasks.
30. 30
void Add(int** a, int** b, int** c, int m, int n)
1 {
2 for (int i = 0; i < m; i++)
3 for (int j = 0; j < n; j++)
4 c[i][j] = a[i][j] + b[i][j];
5 }
覯 s/e 觜 螻
1 0 0 (0)
2 1 () ()
3 1 () ()
4 1 () ()
5 0 1 (0)
豐 螻 ()
s/e : ろ 螻 (Step per Execution)
31. 31
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
螳 覦一伎 , Best Case
谿城 螳 middle 覦襦 蟆曙(9襯 蟆)
2 5 9 11 15 18
2 5 11 15 189
left
(0)
right
(5)
middle
(0+5)/2=2.52
, 螳 覲旧° (1)!
x = 9, a[middle] = a[2] = 9企襦
9螳 豺 2襯 覦
32. 32
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
Worst Case 覦一伎 螳 蟆
(24襯 蟆)
2 5 11 15 189
left
(0)
right
(5)
middle
(0+5)/2=2.52
x = 24, a[middle] = a[2] = 9企襦
left襯 3朱 覦蠑 れ
33. 33
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 11 189 15
left
(3)
right
(5)
middle
(3+5)/2=4
x = 24, a[middle] = a[4] = 15企襦
left襯 5襦 覦蠑 れ
34. 34
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n - 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle - 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 119 15 18
left = right
(5)
middle
(5+5)/2=5
x = 24, a[middle] = a[5] = 18企襦
left襯 6襦 覦蠑 れ
讌襷, while (left <= right) 覓語
left = 6, right = 5企襦 while (false),
while 覓語 觜碁り -1 覦
, 螳 覲旧°?
35. 35
int BinarySearch(int* a, const int x, const int n)
{ // Search the sorted array a[0], ... , a[n-1] for x.
int left = 0, right = n 1;
while (left <= right)
{ // There are more elements
int middle = (left + right) / 2;
if (x < a[middle]) right = middle 1;
else if (x > a[middle]) left = middle + 1;
else return middle;
} // End of while
return -1; // Not found
}
2 5 119 15 18
2 5 11 189 15
2 5 11 15 189
螳 覲旧° 螻一 旧 while 覓語 朱 覦覲給螳?
覿覿 朱 襷 螳 蟯蟇
覿覿 螳 覩襦 (1)
left right
left right
/2
/4
left = right
+(1)
+(1)
磯殊, 螳 覲旧°
=
2
+ 1 !