Competitive Programming Solutions: Niuke Summer Multi-School Training Camp 2024

Given an integer x, construct a y < x such that gcd(x, y) = x ⊕ y (bitwise XOR). The solution is to take y = x - lowestSetBit(x). If x is a power of 2, then no solution exists. #include<iostream> #include<cmath> using namespace std; using ll = long long; void solve() { ll x; cin >> x; ll lowest_bit = x & ...

Posted on Tue, 04 Aug 2026 16:19:06 +0000 by VLE79E

Understanding Shell Sort: A Generalized Insertion Sort Algorithm

Core Principles of Shell Sort Shell sort operates as a generalized optimization of the insertion sort algorithm. While standard insertion sort is efficient for small or nearly sorted datasets, its performance degrades significantly on large lists because elements can only move one position at a time. Proposed by Donald Shell in 1959, this algor ...

Posted on Tue, 04 Aug 2026 16:09:19 +0000 by brotherhewd

Designing a Linked List (LeetCode 707)

get(index): Get the value of the index-th node in the linked list. If the index is invalid, return -1. addAtHead(val): Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. addAtTail(val): Append a node of value val as the last element of the linked lis ...

Posted on Sun, 02 Aug 2026 16:56:14 +0000 by quikone

Implementing a Contact Management System in C

Building a Small Address Book in C Mini Project: Address Book System Requirements: Store contact information: Name, Gender, Phone Maximum capacity: 50 contacts Functional requirements: Add a contact Delete a contact by name Modify a contact by name Search contacts by name or phone (supports fuzzy search) Display all contacts Exit the system ...

Posted on Sun, 02 Aug 2026 16:21:01 +0000 by benjy

Southwest University for Nationalities 2023 Programming Competition Selection Problems and Solutions

L1-1 Thank You, Karl! This problem requires outputting a specific formatted string. The output contains an emoticon with escaped backslashes. Reference Implementation #include <bits/stdc++.h> using namespace std; int main() { cout << "Thank You Karl!\\\\(>_<)/" << endl; return 0; } L1-2 It's Fantasy ...

Posted on Sat, 01 Aug 2026 16:26:03 +0000 by bender

Binary Tree Algorithm Challenges: Minimum Difference, Modes, and Lowest Common Ancestor

Finding the Minimum Absolute Difference in a BSTGiven the properties of a Binary Search Tree (BST), an in-order traversal processes nodes in ascending order of their values. Consequently, the smallest absolute difference between any two nodes in the tree must exist between two adjacent nodes in this sorted sequence. We can implement a recursive ...

Posted on Thu, 30 Jul 2026 16:47:13 +0000 by MitchEvans

Topological Sorting: Detecting DAGs and Resolving Competition Rankings

Topological sorting is a fundamental graph algorithm with critical applications in determining whether a directed graph contains cycles. This technique is extensively used in build systems, course scheduling, and dependency resolution. Problem A: Topological Sort for Directed Acyclic Graphs The core challenge involves producing a valid topologi ...

Posted on Thu, 30 Jul 2026 16:35:06 +0000 by dlester

Understanding HashCode: Collision Resolution and Practical Implications in HashMap

What is a Hash Collision? When discussing hash collisions, we need to understand the fundamental issue: different objects processed through the same hash algorithm produce identical hash values. Consider HashMap's internal structure—a combination of an array with linked lists. When a key-value pair is inserted, the hash code determines which ar ...

Posted on Wed, 29 Jul 2026 16:18:10 +0000 by jonsjava

Data Structures Implementations: Leaf Counting, Linked List Insertion, and Unique Like Ranking

Counting Leaf Nodes in a Binary Tree Calculate the number of leaf nodes within a binary tree. A leaf node is defined as a node where both the left and right child pointers are null. #include <stdio.h> #include <stdlib.h> typedef char ElemType; typedef struct BiTNode { ElemType data; struct BiTNode *lchild, *rchild; } BiTNod ...

Posted on Tue, 28 Jul 2026 16:53:11 +0000 by glence

C# Collections, Sorting, Generics, and Data Structures

Why Use Collections? Arrays have fixed sizes—once allocated, their length cannot change. This rigidity leads to either wasted memory (if oversized) or the need for code changes when requirements evolve. Collections, in contrast, dynamically resize as elements are added or removed. Generic List<T> List<T> is a strongly typed collecti ...

Posted on Tue, 28 Jul 2026 16:32:46 +0000 by Nymphetamine