[Topcoder] srm158 div2 Summary

Source: Internet
Author: User

250 question: given a four-character string initial and rotate, and then giving another string current, How many times does the current get through rotate by initial?

Simply simulate the rotate.

Code: tirerotation

500 question: given an equation, determine whether the equation is true in X-base (X is in 2 ~ 20 ).

My idea is to write a baseadd statement to simulate the addition under hexadecimal X, and then calculate the sum of the two integers in the equation in hexadecimal notation, then it is equal to the comparison in the equation.

The implementation of baseadd is similar to the addition of large integers. It converts integers into strings and then simulates addition and bitwise.

Code: basemystery

After reading the code of the great gods, I almost had to vomit blood, and the original Java integer. parseint has a parameter that can be used to convert a string to an X-base number. Then, two X-base numbers can be directly added with +. Therefore, you do not need to implement baseadd, gray is often simple. Below are some javadoc of integer. parseint:

     * Parses the string argument as a signed integer in the radix     * specified by the second argument. The characters in the string     * must all be digits of the specified radix (as determined by     * whether {@link java.lang.Character#digit(char, int)} returns a     * nonnegative value), except that the first character may be an     * ASCII minus sign {@code ‘-‘} ({@code ‘\u005Cu002D‘}) to     * indicate a negative value or an ASCII plus sign {@code ‘+‘}     * ({@code ‘\u005Cu002B‘}) to indicate a positive value. The     * resulting integer value is returned.

The following are examples:

     * parseInt("0", 10) returns 0     * parseInt("473", 10) returns 473     * parseInt("+42", 10) returns 42     * parseInt("-0", 10) returns 0     * parseInt("-FF", 16) returns -255     * parseInt("1100110", 2) returns 102     * parseInt("2147483647", 10) returns 2147483647     * parseInt("-2147483648", 10) returns -2147483648     * parseInt("2147483648", 10) throws a NumberFormatException     * parseInt("99", 8) throws a NumberFormatException     * parseInt("Kona", 10) throws a NumberFormatException     * parseInt("Kona", 27) returns 411787

1000 question: This is the Super simplified version of the "Gemma Maze". Given a board, I would like to ask how many moves are possible, A move operation exchanges an element with the eight elements around it (if the eight elements exist ), it is required that three consecutive lines or columns of characters can be generated after the exchange.

You can simulate it and implement three functions by yourself: The exchange function to determine whether the current exchange takes effect and whether a function at a certain position is valid; then, exchange each element in the board with the element above and on the right to see if a valid exchange can be obtained (only the above and the right are exchanged to avoid repeated exchanges ).

Code ": gems

[Topcoder] srm158 div2 Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.