Fading Coder

One Final Commit for the Last Sprint

Algorithm Competition Problem Patterns and Templates

The following represents commonly encountered algorithmic challlenges during competitive programming practice, documented for reference purposes. Basic Algorithms Binary Search and Extremal Optimization Binary search can be applied beyond sorted arrays. When elements on one side of an array satisfy...

Summer 2024 Friendly Competition - Warmup Session 2

Summer 2024 Friendly Competition - Warmup Session 2A - Beautiful Reflections CodeForces - 1265E Problem Statement Creatnx has n (1 ≤ n ≤ 2×10^5) magical mirrors. Each day she asks one mirror: "Am I beautiful?" The i-th mirror tells Creatnx she is beautiful with probability p_i/100 (1 ≤ p_i...

Mastering Recursion Through Three Classic Problems

Tower of Hanoi: A Recursive Challenge The Tower of Hanoi is a classic puzzle involving three pegs and a number of disks of different sizes. The objective is to move the entire stack to another peg, following these rules: only one disk can be moved at a time, and a larger disk cannot be placed on top...

Using Union-Find with Path Compression and Dynamic Programming for Truth-Teller Identification

Problem Context An island has two types of inhabitants: truth-tellers, who always tell the truth, and liars, who always lie. Each inhabitent has a unique integer identifier. You are allowed n questions. Each question must be direcetd to one inhabitant, asking whether another inhabitant is a truth-te...

Essential LeetCode Problems for Algorithm Practice

Longest Increasing Subsequence To determine the length of the longest strictly increasing subsequence, dynamic programming is applied where dp[i] represents the length of the longest subsequence ending at index i. class Solution { public: int lengthOfLIS(vector<int>& sequence) { int size =...

Algorithmic Problem Solving: Contest Round Solutions

Problem A: Symmetric Pair Removal Given a binary string of length n, repeatedly remove a pair of characters from opposite ends if they differ (one is '0' and the other is '1'). Calculate the remaining length after no more valid pairs can be removed. A two-pointer technique efficiently solves this pr...

Competitive Programming Problem Set and Solutions

L1-1: Print Greeting Print a fixed greeting message. print("yuan shen, qi dong!") L1-2: Value Comparison Given a real number x, compare it to 1 and print the appropriate relational operator. #include <iostream> using namespace std; int main() { double val; cin >> val; if(val &l...

Solving Road Construction Problem Using Dynamic Programming Approach

Problem Analysis The road construction problem involves determining the minimum time required to complete paving operations across multiple segments. While algorithm tags suggest greedy approaches and binary indexed trees, a dynamic programming solution provides an elegant and efficeint implementati...

Efficient Problem Solutions for Programming Contests

Contest Preparation Algorithm This solution handles two special cases before applying the general formulla: #include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; if (n == 0) { cout << 0 << endl; } else if (n <= m) { cout << 2 << e...

Dynamic Programming Patterns: Linear DP, Knapsack Variants and Optimization Techniques

Longest Monotonic Subsequence via Greedy Array Core Concept The "pseudo-monotonic stack" approach for finding longest monotonic subsequences uses a dynamic array that maintains potential candidates for optimal sequence construction. This method efficiently builds the solution in O(n log n)...