Problem 1 OO solution code has been updated and continues to accelerate.

Source: Internet
Author: User

I posted a solution to the second question yesterday. You gave me a lot of comments and gained a lot. Continue to issue the first question today. We can see that everyone is using OO to solve the problem, but Oo should not be slower, right ..

For more information, seeAlgorithm.

With the OO design concept,CodeIf there are too many files, you don't need to paste them. Package and download/files/Pandora/t1_oo_fast.zip (add the comparison test code)

I don't know whether Oo is complete or not. I am doing it all by feeling. Let's give more comments.

 

Test


 

To make it easier for students to browse, copy the questions as follows:

First algorithm question (250 points)

It is said that when you walk to work, you pass through a farmland where radishes are planted. The shape of this field is a rectangular grid. The J-character of the I-th element of field indicates the number of radishes contained in the grid in column J of the I-th row of the field. We define a lattice as the sum of the numbers of radishes in all its surrounding grids. The grids around it include the upper, lower, left, and diagonal adjacent grids, with a maximum of eight, there will be fewer grids on the boundary of the field. If there is no grid around a grid, it is special to 0.
Return the number of all grids (including a and B) between A and B in a field to a particular extent ).
Definition
Class: numberfield
Method: countspecialnumbers
Parameters: String [], Int, int
Returns: int
Method Signature: int countspecialnumbers (string [] field, int A, int B)
(Be sure your method is public)


 
Constraints
-Field contains 1 to 50 elements, including 1 and 50.
-Each field element contains 1 to 50 characters, including 1 and 50.
-Each element of field contains the same number of characters.
-The characters of each field element are from '0' to '9.
-A ranges from 0 to 100, including 0 and 100.
-B ranges from A to 100, including a and 100.
Examples
0)
{& Quot; 111 & quot ",
"111 ",
"111 "}
4
8

Returns: 5
In this field, the lattice in the corner is 3, the lattice in the middle is 8, and the four other grids are 5.

1)
{& Quot; 111 & quot ",
"141 ",
"111 "}
4
8

Returns: 9
Now all nine grids meet the requirements.

2)
{& Quot; 2309 & quot ",
"0239 ",
"2314 "}
5
7

Returns: 3

 

3)
{& Quot; 924 & quot ",
"231 ",
"390 ",
"910 ",
"121 "}
31
36

Returns: 0

 

4)
{"5 "}
3
8

Returns: 0

 

5)
{& Quot; 1234567890 & quot ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 ",
"1234567890 "}
3
18

Returns: 26

 

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.