Essential Greedy Algorithm Concepts and Classic Problem Solutions
Core Idea of Greedy Algorithms
The essence of a greedy strategy is to build a globally optimal solution by repeatedly making locally optimal choices. The typical workflow involves:
Breaking the problem into smaller subproblems.
Determining a suitable greedy criterion.
Obtaining the best posssible choice for each subproblem.
Aggregating these l ...
Posted on Thu, 17 Sep 2026 16:15:36 +0000 by lancet2003
Solutions to AtCoder Beginner Contest 055 Problems
Problem A
Each meal costs 800 yen. For every 15 meals purchased, a refund of 200 yen is issued. Given $ x $, the total number of meals consumed, compute the net expenditure.
The formula is:
$$
800x - \left\lfloor \frac{x}{15} \right\rfloor \cdot 200
$$
Problem B
After $ N $ workouts, where initial strength is 1 and each $ i $-th workout multipl ...
Posted on Fri, 11 Sep 2026 16:45:57 +0000 by YOUAREtehSCENE
Solutions for 2020 ICPC Asia Shenyang Regional Contest Problems
Problem D: Journey to Un'Goro
For small sequence lengths (n ≤ 20), iterate through all possible binary strings of length n. For each string, compute the prefix sum of red characters ('r' represented as 1, 'b' as 0). Count the number of subarrays where the sum of reds is odd. Track the maximum count and collect all configurations achieving it.
F ...
Posted on Wed, 19 Aug 2026 16:39:07 +0000 by andreas
Programming Competition: Problem Analysis and Solutions
Competition Details
Duration: 3 hours
Start Time: 2026/1/30 8:00
End Time: 2026/1/30 11:00
Difficulty Level: High
Final Score: 340
Lost Points: 60
Problem Set
Problem 1: Element Removal Sum
Description
Given a sequence of integers A of length N and an integer M, determine if it's possible to remove exactly one element from A such that the ...
Posted on Tue, 11 Aug 2026 16:13:55 +0000 by devangel
SMU Summer 2023 Contest Round 5 Solutions
A. Points in Segments
An approach with a time complextiy of $ \mathcal{O}(n \times m) $ works well for small data ranges. The idea is to mark each point within the given intervals and then count how many points are not marked.
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(f ...
Posted on Sat, 01 Aug 2026 16:53:59 +0000 by minus4
AtCoder Beginner Contest 159: Complete Editorial and Solutions
A - The Number of Even Pairs
Given (n) even numbers and (m) odd numbers, count the number of ways to choose two distinct numbers such that their sum is even. A sum is even only if both numbers have the same parity. The number of ways to pick two evens is (\binom{n}{2} = n(n-1)/2), and for two odds its (\binom{m}{2} = m(m-1)/2). The total is the ...
Posted on Sun, 19 Jul 2026 16:34:57 +0000 by mc2007
Solving Complex SQL Problems: A Micro-to-Macro Approach for Daily New User Retention
Problem Source
This problem is from the SQL section of Niuke's Big Company Real Interview Questions, specifically scenario 02: User Growth (Baidu Information Flow), question SQL164: Calculate the next-day retention rate of new users for each day in November 2021.
Shifting from Macro-to-Micro to Micro-to-Macro
Previous chapters emphasized a top- ...
Posted on Sun, 19 Jul 2026 16:33:12 +0000 by rockindano30
Solutions to a Set of Algorithmic Challenges from an ACGO Ranking Contest
Six problems drawn from a competitive programming rating competition are analysed below. Every solution is accompanied by both C++ and Python implementations. Keep in mind that Python code may run slower and care should be taken with complexity constants.
Problem 1 – Output a Digit Different from the Product
Given two integers a and b, print an ...
Posted on Thu, 16 Jul 2026 16:13:10 +0000 by machiavelli1079
Dynamic Programming Problems
It is clear that S represents the initial magic value, k is the number of selected items, and x is given in the problem.
Noting that x is large but k and n are small, we can define a state that tracks the i-th item, the number of selected items j, and the sum modulo k as l. The goal is to maximize the initial magic value, as higher values reduc ...
Posted on Thu, 09 Jul 2026 17:14:51 +0000 by Virii
SMU Spring 2023 Trial Contest Round 9
A. Incorrect Subtraction
Simulate the process of subtracting 1 from the last digit of a number for k times. If the last digit is 0, remove it instead.
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 2e3 + 10, mod = 1e9 +7;
typedef pair<int,int> PII;
int n,m,t,k;
vector<int& ...
Posted on Fri, 03 Jul 2026 16:28:51 +0000 by mella