Netease youdao puzzle topcoder online challenge 350 points

Source: Internet
Author: User



Topcoder for the first time has some different feelings.

 

I have never heard of it before. After working for a while, I found that the knowledge structure is not complete. I especially want to add some knowledge about algorithms.

So if you have time to do the topcoder, one is to change the code writing environment. After all, the time requirement of contest is more urgent. Another algorithm that you are not familiar with can

Inspire us to read and search.

 

So this weekend, I went online to do the second round of challenge that NetEase had a tough problem (the first round can get a t-shirt, which is good and comfortable to wear D :), the scores of the three questions are 350,500,100 and 0 respectively. The first question is understood and written, but is dropped by others;

The second question is about understanding the meaning of the question. The algorithm is vague and I don't know how to write it. The last time is too late to finish writing. Question 3: I have no time to read it.

 

Now, it seems that time is very important to grasp the issue and propose solutions as soon as possible.

 

The probability of being caught by Cha is very high, which indicates that everyone has the same problem with algorithms. Looking at it, there is actually a lot of logic confusion. At least my first question later found that there was indeed a problem of thinking. Lesson: before writing code, the algorithm must be clear and the logic is complete.

 

I had to admire acrush's algorithm. Another feeling is: when data or data volume changes, pay special attention to the following two problems:

1. Can violence solve the problem?

2. There are often better algorithms.

 

The following is a 350 question and a Java version rewritten based on acrush code.

 

Netease youdao puzzle topcoder
Online Challenge No. 350
Sub-questions

Problem Statement

If two consecutive digits are not the same in decimal format, it is called "No-duplicated plural ". For example, 105
, 1234
And 12121
All are "not complex", and 11
, 100
And 1225
No.

Given a long
Type Number
, Returns a value greater than.
The minimum value is "no complex ".

Definition

Class: unrepeatingnumbers

Method: getnext

Parameters: Long

Returns: Long

Method Signature: Long getnext (long)

(Be sure your method is public)

Constraints-

A
Value Range: [0, 10 ^ 17]
Note that it is a closed interval.

Examples

0)

54

Returns: 56

Greater than 54
The minimum number is 55.
, But 55
It is not "not a complex number ". The next digit is 56.
.

1)

10

Returns: 12

2)

9

Returns: 10

3)

98

Returns: 101

99
And 100
None of them are "not complex", but 101
Yes.

4)

21099

Returns: 21201

This problem statement is the exclusive and proprietary
Property of topcoder, Inc. Any unauthorized use or reproduction of this
Information without the prior written consent of topcoder, Inc. is strictly
Prohibited. (c) 2003, topcoder, Inc. All rights reserved.

 

Java code:


Public class unrepeatingnumbers {</P> <p> Public static void main (string [] ARGs) {</P> <p> unrepeatingnumbers UN = new unrepeatingnumbers (); <br/> CIN = new partition (system. in); <br/> while (true) <br/>{< br/> system. out. println (UN. getnext (CIN. nextlong (); <br/>}< br/> Public long checkanditerate (long N) <br/>{< br/> stringbuffer S = new stringbuffer (string. valueof (n); <br/> for (INT I = 0; I + 1 <S. length (); I ++) <br/>{< br/> If (S. charat (I) = S. charat (I + 1) <br/>{< br/> long P10 = 1; <br/> for (Int J = I + 2; j <S. length (); j ++) <br/>{< br/> S. setcharat (J, '0'); <br/> P10 * = 10; <br/>}< br/> N = long. parselong (S. tostring () + P10; <br/> return N; <br/>}< br/> return-1; <br/>}< br/> long getnext (long a) <br/>{< br/> A ++; <br/> long temp = 1; <br/> while (temp> 0) <br/>{< br/> temp = checkanditerate (a); <br/> If (temp> 0) A = temp; <br/>}< br/> return a; <br/>}< br/>}

 

I hope to help you. The essence of algorithms lies in efficiency.

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.