Giter Club home page Giter Club logo

matthewsamuel95 / acm-icpc-algorithms Goto Github PK

View Code? Open in Web Editor NEW
2.0K 2.0K 1.3K 2.4 MB

Algorithms used in Competitive Programming

C++ 48.94% Java 17.81% Python 12.00% C 11.06% Scala 0.21% Haskell 0.33% Erlang 0.16% JavaScript 1.75% PHP 0.17% Ruby 0.54% Go 0.66% Kotlin 0.62% Common Lisp 0.68% C# 3.60% Brainfuck 0.02% Lua 0.08% Perl 6 0.03% Swift 0.22% Ada 1.12%
acm acm-icpc acm-icpc-handbook algorithm algorithm-competitions algorithms icpc programming

acm-icpc-algorithms's Introduction

ACM-ICPC Algorithms

Introduction to ACM-ICPC

ACM International Collegiate Programming Contest (abbreviated as ACM-ICPC or ICPC) is an annual multi-tiered competitive programming competition among the universities of the world.

Alternately, we can say that the International Collegiate Programming Contest is an algorithmic programming contest for college students.

  • Teams of three, representing their university, work to solve real-world problems, fostering collaboration, creativity, innovation, and the ability to perform under pressure.
  • Through training and competition, teams challenge each other to raise the bar on what could be done.
  • Quite simply, it is the oldest, largest, and most prestigious programming contest in the world.

Purpose of ACM-ICPC Algorithms

ACM-ICPC Algorithms is a collection of important algorithms and data structures used to solve questions in this worldwide olympiad. It aims to provide solutions in various languages as per ICPC 2018 WF, including:

  • C
  • C++
  • Java
  • Python (2 & 3)
  • Kotlin
For more information, visit: Official Website of ICPC

If you wish to contribute, please refer to the contributor guidelines.

Table of Contents :

acm-icpc-algorithms's People

Contributors

5ar5kovic avatar 96mohitm avatar amarnath-v avatar amulyagaur avatar anirudherabelly avatar arpantarkas avatar artistic18 avatar ash12345678987654321 avatar batchunag avatar destinyson7 avatar gotham13 avatar jeffin143 avatar justanotherlad avatar kevinlu avatar klien1 avatar kyscg avatar luqluk avatar matthewsamuel95 avatar mmani9199 avatar omarkimo avatar pedronc18 avatar pikonha avatar pockemon avatar shakib609 avatar shalithasuranga avatar shikharp16 avatar shobhitbehl avatar sudesh1611 avatar thiagoyeds avatar yassin64b avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acm-icpc-algorithms's Issues

Write a program to calculate pow(x,n)

Consider values for negative n

Implement pow(x, n), which calculates x raised to the power n (x^n).

Examples
Input: 2, -2
Output : 0.25

Input: 2.00000, 10
Output: 1024.00000

Push code to Math/Power/{ur file}

Largest area rectangular sub-matrix with equal number of 1’s and 0’s

Given a binary matrix. The problem is to find the largest area rectangular sub-matrix with equal number of 1’s and 0’s.

Input : mat[][] = { {0, 0, 1, 1},
{0, 1, 1, 0},
{1, 1, 1, 0},
{1, 0, 0, 1} }
Output : 8 sq. units
(Top, left): (0, 0)
(Bottom, right): (3, 1)

Input : mat[][] = { {0, 0, 1, 1},
{0, 1, 1, 1} }
Output : 6 sq. units

Time Complexity : O(Row x Col)

Group Anagrams

Given an array of strings, group anagrams together.

Example
Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
Output:
[
  ["ate","eat","tea"],
  ["nat","tan"],
  ["bat"]
]

Place code in String subfolder

Hamiltonian Cycle

A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path such that there is an edge (in graph) from the last vertex to the first vertex of the Hamiltonian Path.

Determine whether a given graph contains Hamiltonian Cycle or not. If it contains, then print the path. Following are the input and output of the required function.

image

alt text

Next power of 2

Write a function that, for a given no n, finds a number p which is greater than or equal to n and is a smallest power of 2.

Input  : n = 17
Output : 32     

Input  : n = 32
Output : 32     

Check for balanced parentheses in an expression

Given an expression string exp , write a program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp. For example, the program should print true for exp = “[()]{}{()()}” and false for exp = “[(])”

4 Sum O(n^2Logn)

Given an array of integers, find any one combination of four elements in the array whose sum is equal to a given value X.
For example, if the given array is {10, 2, 3, 4, 5, 9, 7, 8} and X = 23, then your function should print “3 5 7 8” (3 + 5 + 7 + 8 = 23).

Put code in Hashing

Longest Common Increasing Subsequence (LCS + LIS)

Given two arrays, find length of the longest common increasing subsequence [LCIS] and print one of such sequences (multiple sequences may exist)

Suppose we consider two arrays –
arr1[] = {3, 4, 9, 1} and
arr2[] = {5, 3, 8, 9, 10, 2, 1}

The answer would be {3, 9} as this is the longest common subsequence which is increasing also.

Contributing.md

Give instructions how to follow the file structure and create a pull request

Dynamic Programming Problems

longest increasing subsequence

The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. For example, the length of LIS for {10, 22, 9, 33, 21, 50, 41, 60, 80} is 6 and LIS is {10, 22, 33, 50, 60, 80}.

3 Sum

Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. If there is such a triplet present in array, then print the triplet and return true. Else return false. For example, if the given array is {12, 3, 4, 1, 6, 9} and given sum is 24, then there is a triplet (12, 3 and 9) present in array whose sum is 24.

2 Sum solution in C++, with O(n) complexity

You can follow this solution in C++, using HashMap to get O(n) solution.

`#include < map >

using namespace std;

class Solution {
public:
vector twoSum(vector &numbers, int target) {
int len = numbers.size();
map<int, int> r;
vector rr;
for (int i = 0; i < len; i ++) {
if (r.find(numbers[i]) == r.end()) { // if not exist
r[numbers[i]] = i; // add it to the map
}
int j, num = target - numbers[i];
if ((r.find(num) != r.end()) && ((j = r[num]) < i)) {
rr.push_back(j + 1);
rr.push_back(i + 1);
return rr;
}
}
return rr;
}
};`

Square root of an integer

Implement int sqrt(int x).

Compute and return the square root of x, where x is guaranteed to be a non-negative integer.

Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned.

Given an integer x, find square root of it. If x is not a perfect square, then return floor(√x).

Examples:
Input: x = 4
Output: 2

Input: x = 11
Output: 3

Subset Sum Problem

Subset Sum Problem

Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.

Examples: set[] = {3, 34, 4, 12, 5, 2}, sum = 9
Output: True //There is a subset (4, 5) with sum 9.

Largest Rectangular Area in a Histogram

Find the largest rectangular area possible in a given histogram

where the largest rectangle can be made of a number of contiguous bars. For simplicity, assume that all bars have same width and the width is 1 unit.

For example, consider the following histogram with 7 bars of heights {6, 2, 5, 4, 5, 1, 6}. The largest possible rectangle possible is 12 (see the below figure, the max area rectangle is highlighted in red)

3 Sum O(n^2)

Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. If there is such a triplet present in array, then print the triplet and return true. Else return false. For example, if the given array is {12, 3, 4, 1, 6, 9} and given sum is 24, then there is a triplet (12, 3 and 9) present in array whose sum is 24.

Put the code in Hashing/3_Sum/{ur file}

Make a .gitignore

please write a gitignore that at least considers for .pyc and a.out and others

Count all possible paths from top left to bottom right of a mXm matrix

The problem is to count all the possible paths from top left to bottom right of a mXm matrix with the constraints that from each cell you can either move only to right or down

Example

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

Top K Frequent Words

Given a non-empty list of words, return the k most frequent elements.

Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.

Example 1: Input: ["i", "love", "leetcode", "i", "love", "coding"], k = 2 Output: ["i", "love"] Explanation: "i" and "love" are the two most frequent words. Note that "i" comes before "love" due to a lower alphabetical order.

Example 2: Input: ["the", "day", "is", "sunny", "the", "the", "the", "sunny", "is", "is"], k = 4 Output: ["the", "is", "sunny", "day"] Explanation: "the", "is", "sunny" and "day" are the four most frequent words, with the number of occurrence being 4, 3, 2 and 1 respectively.

Dynamic Programming Problems

Coin change

Given a value V, if we want to make change for V cents, and we have infinite supply of each of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the change?
Input: coins[] = {25, 10, 5}, V = 30
Output: Minimum 2 coins required
We can use one coin of 25 cents and one of 5 cents

Input: coins[] = {9, 6, 5, 1}, V = 11
Output: Minimum 2 coins required
We can use one coin of 6 cents and 1 coin of 5 cents

Maximum size square sub-matrix with all 1s

Given a binary matrix, find out the maximum size square sub-matrix with all 1s.

Edit Distance

Given two strings str1 and str2 and below operations that can performed on str1. Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.

Insert
Remove
Replace
All of the above operations are of equal cost.

Input: str1 = "geek", str2 = "gesek"
Output: 1
We can convert str1 into str2 by inserting a 's'.

Input: str1 = "cat", str2 = "cut"
Output: 1
We can convert str1 into str2 by replacing 'a' with 'u'.

Input: str1 = "sunday", str2 = "saturday"
Output: 3
Last three and first characters are same. We basically
need to convert "un" to "atur". This can be done using
below three operations.
Replace 'n' with 'r', insert t, insert a

Shortest Uncommon Subsequence

Given two strings S and T, find length of the shortest subsequence in S which is not a subsequence in T. If no such subsequence is possible, return -1. A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. A string of length n has 2^n different possible subsequences.

Input : S = “babab” T = “babba”
Output : 3
The subsequence “aab” of length 3 is
present in S but not in T.

Input : S = “abb” T = “abab”
Output : -1
There is no subsequence that is present
in S but not in T.

Algorithm should have
Time complexity : O(mn^2)
Space Complexity : O(mn)

2 Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

Compute sum of digits in all numbers from 1 to n

Given a number x, find sum of digits in all numbers from 1 to n.

Input: n = 5
Output: Sum of digits in numbers from 1 to 5 = 15

Input: n = 12
Output: Sum of digits in numbers from 1 to 12 = 51

Input: n = 328
Output: Sum of digits in numbers from 1 to 328 = 3241

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.