This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include<numeric> | |
| #include<climits> | |
| #include <algorithm> | |
| #include<utility> | |
| #include<iostream> | |
| using namespace std; | |
| #define check(n,lim)(0<=(n)&&(n)<=(lim)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <map> | |
| #include <utility> | |
| #include <queue> | |
| #include <algorithm> | |
| using namespace std; | |
| template<class T> | |
| class MaxHeap { | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int height(node* root) { | |
| if (!root) return 0; | |
| int leftHeight = 0, rightHeight = 0; | |
| if (root->left) | |
| leftHeight = 1 + height(root->left); | |
| if (root->right) | |
| rightHeight = 1 + height(root->right); | |
| return max(leftHeight, rightHeight); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <map> | |
| #include <utility> | |
| #include <queue> | |
| #include <algorithm> | |
| using namespace std; | |
| class PriorityVenues { | |
| public: | |
| PriorityVenues()=default; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bool has_cycle(node* head) { | |
| if (!head || !head->next) return false; | |
| node* slow, *fast; | |
| slow = fast = head; | |
| while (true) { | |
| slow = slow->next; | |
| if (fast->next) | |
| fast = fast->next->next; | |
| if (slow == nullptr || fast == nullptr) | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void deleteList(node* cur); | |
| // Doubly linked list | |
| node* deleteBetween(node* head, node* x, node* y) { | |
| if (x->prev) | |
| x->prev->next = y->next; | |
| else | |
| head = y->next; | |
| if (y->next) | |
| y->next->prev = x->prev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdexcept> | |
| #include <iostream> | |
| #include <memory> | |
| #include <cstring> | |
| #include <cmath> | |
| using namespace std; | |
| template<class T> | |
| class RingBuffer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstring> | |
| #include <string> | |
| using namespace std; | |
| // returns true if A is a fading palindome | |
| bool ifp(char* A) { | |
| int i, n = strlen(A); | |
| for (i = 0; i < n/2; ++i) { | |
| // we need to check the palindome invariant A[i] == A[n-i-1] and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| void makeBowTie(int h) { | |
| int i, j, k, s; | |
| for (i = 1; i <= h; ++i) { | |
| s = 2*i-1; | |
| s = h - abs(h - s); | |
| for (j = 0; j < s; ++j) cout << '*'; | |
| for (j = 0; j < 2*h - 2*s; ++j) cout << ' '; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| using namespace std; | |
| // 1 - 3 + 5 - 7 + 9 ... +/- n | |
| // recursive | |
| int f1(int n) { | |
| if (n == 1) return 1; | |
| if (n % 2 == 0) n--; |