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

Identifying a Valid Row Subset in a Binary Matrix via Bitmasking

In a binary matrix of size m x n, a subset of rows is considered "good" if, for every column, the sum of the elements in that column does not exceed half the size of the subset. Formally, if the subset conntains k rows, the sum of each column must be less than or equal to floor(k / 2). The goal is to return the indices of such a subse ...

Posted on Thu, 16 Jul 2026 16:05:53 +0000 by jsinker

Implementing the Factory Method Pattern for Web Crawlers

Simple Factory Limitations Basic factory implementations often suffer from inflexibility when new types need to be added. Consider a web crawler system with different spider types: enum class CrawlerType { TEXT, IMAGE, }; class BasicSpiderFactory { public: static shared_ptr<Spider> CreateCrawler(CrawlerType type) { sw ...

Posted on Wed, 15 Jul 2026 17:22:13 +0000 by splat78423

Designing Single Header Libraries with Conditional Compilation in C++

Single header libraries often rely on a combination of standard header guards and specific implementation flags to separate declarations from definitions. While both use preprocessor directives, they solve diffferent problems at different stages of the compilation pipeline. 1. The Role of the Header Guard The primary purpose of a standard heade ...

Posted on Wed, 15 Jul 2026 17:10:07 +0000 by mccdave

Implementing Avatar Upload Functionality in Qt

Many users have encountered the avatar upload feature in Qt. Figure 1 should be familiar to most. This article demonstrates how to simulate a similar function, although it may not offer all the advanced features, it can fulfill basic requirements. Figure 1: QQ image upload Before diving into the functionality, I recommend reading a article on i ...

Posted on Wed, 15 Jul 2026 16:29:41 +0000 by jkurrle

Inheritance in C++: A Comprehensive Guide

1. Concept and Definition of Inheritance Inheritance is a fundamental mechanism in object-oriented programming (OOP) that enables code reuse. It allows a new class (derived class) to extend an existing class (base class) by adding new features. Inheritance reflects the hierarchical structure of OOP and represents a cognitive process from simple ...

Posted on Wed, 15 Jul 2026 16:02:11 +0000 by worldworld

AtCoder Beginner Contest 014 - Problem Solutions

Problem A Given a snacks to distribute equally among b people. Snacks cannot be divided. Find the minimum number of additional snacks that need to be purchased. Solution Each person requires ceil(a/b) snacks. Therefore, the total snacks needed is ceil(a/b) * b. The additional snacks required is ceil(a/b) * b - a. int snacks, people; std::cin &g ...

Posted on Tue, 14 Jul 2026 17:33:54 +0000 by ypkumar

Greedy Algorithms in Practice: Assigning Cookies, Longest Wiggle Subsequence, and Maximum Subarray

Fundamentals of Greedy Strategies Greedy algorithms do not follow a rigid template. They essence lies in building a global optimum through a sequence of locally optimal choices. While formal proof of correctness is not mandatory for competitive programming (as long as the solution is accepted), a systematic approach helps: Break the problem in ...

Posted on Tue, 14 Jul 2026 16:22:43 +0000 by hunna03

Smart Pointers in C++ Without Reference Counting

The Problem with Shallow Copying A simple smart pointer implementation that lacks reference counting can suffer from a critical flaw known as the double-free error. This occurs when a copy of the pointer is made, causing both the original and the copy to point to the same underlying resource. When either of these pointers goes out of scope, it ...

Posted on Tue, 14 Jul 2026 16:21:34 +0000 by Jove

Dynamic Programming Approaches for Palindrome String Problems

Counting Palindromic Substrings This section addresses the problem of counting all palindromic substrings within a given string, similar to LeetCode problem 647. Problem Description Given a string s, determine and return the total count of palindromic substrings. A substring is a contiguous sequence of charcaters. A palindromic string reads the ...

Posted on Tue, 14 Jul 2026 16:19:33 +0000 by mdgalib