Skip to main content

Posts

Showing posts with the label codeforces

Codeforces Global Round 6

Codeforces Global Round 6 A. Competitive Programmer According to the problem statement you are given some digits ( 0 - 9 ) , is it possible to make a number using all digits which is divisible by 60 ? To make a number from the digits which is divisible by 60, we need a zero and more than one even digits and digits sum must be divisible by 3. Code : B. Dice Tower According to the the picture given in the problem the sum of any two oppsite side of the dice is 7. Accept top dice , sum of all visible side pips in a dice is 21 - 7 = 14. We can make a tower , which all visible pips is equal to n , if n = 14 * d + 14 + pip n = 14 * D + pip where pip = { 1, 2, 3, 4, 5, 6 } Code :

Checking a fraction x/y contains infinite number of numerals after the decimal point

Infinite fractions \[ \text{When is }\ x \mid y \text{ ?} \ \] x can be represent as \[ {x} = \prod_{i=1}^n p_{i}^{k} \] \[ \text{where}\ p_{i} =\text{ is a prime factor of } {x} \text{ and } {x} \text{ has } {n} \text{ prime factors.} \] \[ \text{Example: }\ {x} = {12} = {2}^{2} \times {3} \] We can represent the y by the same way. x divides y ( x is a divisor of y ) if and only if all prime factors of x are available in y prime factorization and each prime factor (p) power (p^a) in x factorization is less than equal to prime factor (p) power (p^b) in y factorization (a <= b). Or we can say that when GCD(x, y) = x  , x divides y. \[ \text{When is }\ x\nmid y \text{ ?} \ \] y = q * x + r [ where r < x ] When reminder (r) is not equal to 0, y is not divisible by x.  Only when r is not equal to zero there are numbers after the decimal point of fraction p/q. How to get numbers after the decimal point of a fraction ? We recursively do it until MOD = 0. init...

Trie problem in Codeforces Round #470

I could not solve the D. Perfect Security in last night's codeforces contest. In the morning I finally understood that the problem was actually a Trie problem. To solve the problem I used a structure name trie which has two trie type structure zero and one and a counter name cnt. For each trie node the cnt stores the number of zeros or ones in that node. As problem says to minimum XOR values. So, the search operation traversing the same bit node ( bit 1 for one and 0 for zero trie type node ) of the Trie tree. If the search operation fail to found the same bit node with a positive counter values, then the operation check for reverse bit node with positive counter. If the conditions are not satisfied, it stops the search operation. For Trie type node one turned on the return value bit position. value | = (1 << position) . The search operation always reduce the traversing nodes counter by 1, So no need to delete operation for each keys.