Archive | Algorithm

[codeforces] Round #204 (Div. 2) The. Jeff and Digits

Threads: http://codeforces.com/contest/352/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jeff’s got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he’s got? Jeff must make the number without leading […]

[Algorithm] Calculate the square root 2

In a technical interview at the company XXX, a programmer "senior" responsible interview Teo Teo ask a question: "Please write a C program calculate square roots 2 the integer x "Teo chuckled and thought to myself" Company Vietnam leading technology what so ask a question easy. It is not some new guy programming!"And in the blink Teo […]

[Algorithm] Calculate the square of 1 number of n numbers 1

Threads: For the S = 111…11 (n digits 1, decimal system), S ^ 2 properties. Input – First line: number of tests k (to<=40). – k next line, Each line contains the number n – number of digits 1 window. (1 <= n <= 1000000) Output – For each test burn results 1 current. Example Input: 2 1 2 Output: 1 121 Solution: KQ has the form we see for […]

[Algorithm] Calculate the trigonometric functions

The formula for calculating the sine(x) and the other trigonometric functions as follows: VD calculate sine(x) , x per radian may be due to the type of data or some other reason that is only accurate to -27<=x<With x = 27 per radian. In the code above we do not count the function x ^(2i 1) and (2i 1)! apart which means continuity in temp temp = x ^ calculation(2i 1) / (2i 1)! to avoid overflow of the […]

[Algorithm] Listing permutations

I will make the program lists the permutations of {1, 2, …, n} Order dictionaries. For example, with n = 3, I have listed enough 6 conversion: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 So the first permutation is <1, 2, …, a>. Final permutation <n, A-1, …, 1〉. Permutation […]

[Algorithm] PROBLEM GetString

Given a string S of length not exceeding 10 ^ 5, and set A with n elements(n≤100) consisting of ASCII characters, are case sensitive. Look for consecutive substring in S that contain the complete set of characters in A and the shortest length. (Consecutive substring is the string with the characters in the order of A and possible ways […]

[Compound] VMTEST – Try machine

Threads: Compound – VMTEST simply reads each string s check[1] there is'?’ not? and continue to do: If s[1] letters, the browser is out s, if encountered s[in] letters shall not escape, and in “Error !”. If s[1] the number or '-‘ or '.’ then copy clusters (phrases separated by spaces) Change the number, if change is then added to […]

[Algorithm] Ma methods – Magic square

In math fun, Magic matrix of degree n (also known as ma or the magic square) an arrangement of n², usually distinct integers, in a square table so that the total number in each row n, post, and diagonals are equal standard dental Magic square contains the integers from 1 to n². Magic square exists for every standard […]

[Algorithm] Calculate the value of expression

Balan inverse method or expression tree will make new friends learn embarrassing. This is an extremely simple method you can understand and apply the simple expression include 2 operations + and * CEO: 2*5+3+4*3+2 Calculation: If the expression has allowed + then take the first expression + Conversely section final expression if the expression […]

[Algorithm – Java] Calculate the value of the expression suffix – Calculate value of the postfix Equation

The validity of a mathematical expression in infix form of conventional computers will be converted to the inverse Polish notation (suffixes) for the calculation is easy. You can see the transformation algorithm from the element to the suffix in my article. In this article, I will present the method for calculating the value of an expression […]