Iterate It
Consider the following pseudocode, run on an array of length : rep := 0 while A not empty: B := [] for x in A, y in A: if x != y: append absolute_value(x - y) to B A := B rep := rep + 1 Given the values of and array , compute and print the final value of after the pseudocode above terminates; if the loop will never terminate, print -1 instead. Input Format The first line contains a single integer, , denoting the length of array . The second line contai
View Solution →Hamming Distance
You are given a string , consisting of small latin letters 'a' and 'b'. You are also given queries to process. The queries are as follows: C : all the symbols in the string, starting at the , ending at the become equal to ; S : swap two consecutive fragments of the string, where the first is denoted by a substring starting from ending at and the second is denoted by a substring starting at ending at ; R : reverse the fragment of the string that starts at the symbol and ends at
View Solution →Mixing proteins
Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called (you know, protein names can be very complicated). A protein mutates into another one depending on itself and the protein right after it. Scientists determined that the mutation table goes like this: Here rows denote the protein at current
View Solution →Simplified Chess Engine
Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ideas and algorithms to analyze positions and sequences of moves, as well as find tactical ideas. Consider the following simplified version of chess: Board: It's played on a board between two players named Black and White. Pieces and Movement: White
View Solution →Password Cracker
There are n users registered on a website CuteKittens.com. Each of them has a unique password represented by pass[1], pass[2], ..., pass[N]. As this a very lovely site, many people want to access those awesomely cute pics of the kittens. But the adamant admin does not want the site to be available to the general public, so only those people who have passwords can access it. Yu, being an awesome hacker finds a loophole in the password verification system. A string which is a concatenation of o
View Solution →