Solving Programming Problems Using Brute Force Techniques in C/C++

Overview Brute force methods involve systematically enumerating all possible solutions to find valid answers. This approach is particularly useful in competitive programming contexts like the Blue Bridge Cup, where problems often require checking combinations or permutations within defined constraints. Problem Solutions Problem 1: Hundred Coins ...

Posted on Thu, 21 May 2026 17:38:21 +0000 by jacko310592

AtCoder Beginner Contest 002 Solutions

Problem A: Maximum Value Given two positive integers as input, output the larger value. Solution Simply compare the two values and output the maximum. #include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << max(a, b) << endl; return 0; } Problem B: Remove Vowel ...

Posted on Wed, 20 May 2026 21:00:00 +0000 by HostingTrade

Introduction to Segment Trees

What is a Segment Tree? A segment tree is a binary tree-based advanced data structure that supports flexible range operations. Unlike a Fenwick Tree (Binary Indexed Tree) which is limited to simple point update/range query use cases, segment trees can handle range updates with point queries, and even full range updates with range queries effici ...

Posted on Wed, 20 May 2026 07:33:16 +0000 by Stryks

Solutions for Codeforces Round 997 (Div. 2) Problems

Problem Link Approach: For this problem, we need to calculate the perimeter of a shape formed by moving right and up. The perimeter can be determined using the formula: ((steps_up + width) + (steps_right + width)) * 2. This accounts for the outer boundaries of the shape. Solution Code: #include <iostream> using namespace std; typedef lo ...

Posted on Tue, 19 May 2026 23:19:15 +0000 by MoombaDS

Solutions for AtCoder Beginner Contest 319

Legendary Players A direct mapping from player handles to their respective ratings is required. A hash map provides an efficient and clean way to resolve this without writing multiple conditional statements. #include <iostream> #include <string> #include <unordered_map> using namespace std; int main() { unordered_map< ...

Posted on Tue, 19 May 2026 22:20:14 +0000 by drawmack

Optimizing Number Theory and Graph Algorithms for Competitive Programming

Efficient XOR Sum Calculation Define (f(i) = \oplus_{d|i}d), then compute (\oplus_{i=1}^{n}f(i)) for (n \le 10^{14}). Approach: Count occurrences of each number via floor division blocks and compute interval XOR sums. #include <bits/stdc++.h> using namespace std; using ll = long long; ll prefix_xor(ll x) { if (!x) return 0; ll re ...

Posted on Mon, 18 May 2026 21:50:34 +0000 by lilRachie

Simulating the Pig-Slaying Card Game

Game Overview This problem involves a complex simulation of a card game variant. The objective is to determine the final outcome given initial roles, hands, and a deck of cards, assuming all players follow strict behavioral rules. Victory Conditions Master Pig (MP): Survives while eliminating all Rebel Pigs. Loyal Pig (ZP): Protects the Master ...

Posted on Mon, 18 May 2026 12:50:49 +0000 by rowantrimmer

Solving P7077: Function Calls with Topological Sorting

Problem Statement We are given an array a of length n and m operations. There are three types of operations: Addition: Given x and y, increase a[x] by y. Multiplication: Given x, multip all elements in a by x. Function Call: Given k operation indices c_1, c_2, ..., c_k, execute the operations c_1, c_2, ..., c_k in sequence. The problem guaran ...

Posted on Sun, 17 May 2026 15:38:22 +0000 by Tekron-X

CSP 2025 Simulation Problems - Technical Analysis and Solutions

Problem Set Overview This document presents detailed solutions for four computational problems from a recent programming contest simulation. Each problem requires distinct algorithmic approaches, ranging from greedy selection with block decomposition to probabilistic expectation calculations on bounded domains. The solutions presented have been ...

Posted on Sat, 16 May 2026 11:29:24 +0000 by missdeath

Greedy Algorithm Applications: Digit Removal and Three-Value Sorting

Minimizing a Number by Removing Digits The goal is to take a high-precision positive integer n (up to 240 digits) and remove s digits such that the remaining digits, in their original order, form the smallest possible integer. Problem Strategy A common mistake is to sort the digits and remove largest ones. However, this violates the rule of ma ...

Posted on Thu, 14 May 2026 14:08:55 +0000 by kucing