Testing-Thor Field

Source: Internet
Author: User

"Problem description"

lwins_7k+ (GYZ), Synophia the continent's leading genius magician, created a new magic: the Realm of Thor.
This magic will first form a square grid magic array on the ground, and then summon the Lightning axis in some locations. Note: One location can only have one Thunderbolt axis label present. The Lightning axis always appears at the vertex of the square grid magic array, so we can mark its position with an ordered integer pair (x_i,y_i).
Then, if there are three lightning axis Mark A,b,c satisfied: X_a=x_b, Y_a=y_c, then the Magic will immediately summon a position in the (x_c,y_b) of the Lightning axis, so reciprocating until there is no condition to meet the Lightning axis Standard group so far.
Finally, lwins_7k+ will select a path on the magic array of a square grid and activate them using natural forces, when the magical strength of the Thor field is defined as the lesser of the number of rows/columns that the lightning axis on the path occupies. But because lwins_7k+ just created this magic, if you choose the path of a U-shaped or round-trip sub-path, it will be a magical wizard to bring a certain risk. Therefore, the selected path should not contain a U-shaped subpath or a round-trip sub-path. (Similar to |__ __ __| Such generalized U-shaped path is not possible)
Since the natural forces must be reconciled from the magician's body, the starting point of the path should be the position of the magician, the lower-left corner (0,0) of the square grid magic array.
Now he wants to ask you--the greatest magical strength in the realm of Thor that he can release from the land of the most powerful God-maker of all time, lwins_***, who was born to conceal his true identity. Of course, the path is up to you to choose for him. Even so, as a magical genius, he only cares about the highest mana intensity.

"Input Format"

Input file field.in The first line contains a positive integer n, which indicates the number of data that follows.
Next n rows, each row contains two positive integer x_i,y_i, indicating that there is a lightning axis at (x_i,y_i).

"Output Format"

The output file Field.out contains only one row, which is the highest possible mana strength.

"Input Sample" field

7
1 1
1 1
1 1
1 2
1 3
2 2
3 1

"Output Example"

3

"Data Size"

For 30% data: n<=10, 0<x_i,y_i<=5.
For 80% of data: 0<x_i,y_i<=2000.
For 100% data: n<=15000, 0<x_i,y_i<=5000.

The key is to find out all the points

And then there's a magical way.

Think of rows and columns as N points, respectively

Each time you point (x, y), the column x and row y are used to check the collection and

For the point x, y existence we just check whether the column x and row y are in the same set, if yes, that point x, y exists, otherwise it does not exist (the point on the graph is the meaning of the other graph of connectivity, because it is undirected graph, so and check set is very convenient)

And then 5000*5000 the DP on the line.

1 Const2maxx=5010;3Name='Field';4 var5F:Array[0.. maxx*2] ofLongint;6Dp:Array[0.. Maxx0.. Maxx ofLongint;7 N,mx,my:longint;8 9 functionFind (X:longint): Longint;Ten begin One     ifF[x]=x Thenexit (x); Af[x]:=find (F[x]); - exit (F[x]); - End; the  - functionMax (x,y:longint): Longint; - begin -     ifX>y Thenexit (x); + exit (y); - End; +  A proceduremain; at var - I,j,x1,y1:longint; - begin -      fori:=1  tomaxx*2  Do -f[i]:=i; - read (n); in      fori:=1  toN Do -       begin to read (x1,y1); +         ifX1>mx Thenmx:=X1; -         ifY1>my Thenmy:=Y1; theF[find (x1)]:=find (y1+Maxx); *       End; $      fori:=1  toMx DoPanax Notoginseng        forj:=1  toMy Do -         ifFind (i) =find (J+maxx) Thendp[i,j]:=dp[i-1, J-1]+1 the         ElseDp[i,j]:=max (dp[i,j-1],dp[i-1, j]); + Writeln (Dp[mx,my]); A End; the  + begin - main; $ End.
View Code

Testing-Thor Field

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.