Tju1167 the Settlers of Catan + competition Summary

Source: Internet
Author: User
ArticleDirectory
    • Input Specification
    • Output Specification
    • Sample Input
    • Sample output

WithinSettlers of Catan, The 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities within SS its uncharted wilderness.
You are employed by a software company that just has decided to develop a computer version of this game, and you are chosen to implement one of the game's special rules:

When the game ends, the player who built the longest road gains two extra vicw.points.

The problem here is that the players usually build complex road networks and not just one linear path. Therefore, determining the longest road is not trivial (although human players usually see it immediately ).

Compared to the original game, we will solve a simplified problem here: you are given a set of nodes (cities) and a set of edges (road segments) of length 1 connecting the nodes.
The longest road is defined as the longest path within the network that doesn't use an edge twice. nodes may be visited more than once, though.

Example: The following network contains a road of length 12.

Input Specification

The input will contain in one or more test cases.
The first line of each test case contains two integers: the number of nodesN (2 ≤ n ≤ 25)And the number of EdgesM (1 ≤ m ≤ 25). The nextMLines describeMEdges. Each edge is given by the numbers of the two nodes connected by it. nodes are numbered from0ToN-1. Edges are undirected. nodes have degrees of three or less. The network is not neccessarily connected.
Input will be terminated by two values of 0NAndM.

Output Specification

For each test case, print the length of the longest road on a single line.

Sample Input

 
3 2
 
0 1
 
1 2
 
15 16
 
0 2
 
1 2
 
2 3
3 4
 
3 5
 
4 6
 
5 7
 
6 8
 
7 8
 
7 9
 
8 10
 
9 11
 
10 12
 
11 12
 
10 13
 
12 14
 
0 0

Sample output

 
2
 
12

O -- O
\/\/
O -- o
/\/\
O -- o
\/
O -- o
After reading this question in the competition, I thought it was just a jump in graph theory. After the competition, I consulted looker, who had been searching for 0 ms, just 40 rows.CodeAh.

Sadly, why didn't I think of it during the competition. Reason: we have not yet developed a good idea of recursion, and the data structure is not too strong. Come on.

By the way, e g is very watery in this competition, and almost everyone has passed.

A string processing is very big at the beginning. It was handed over to WA. It was careless to write the lower-case 'K' as 'K!

B. What I did with quickshield is special judge. I didn't see the question "print a blank line after each test case, even after the last one." contributed a wa

H. query the set implementation. First, sort the load of each route from large to small, and add each path in sequence until the start and end nodes can be connected. Then, the load of the current path is output.

C, D, and F are not implemented during the competition. The above is question C. The question D team queue should be implemented through a linked list. The last hour has contributed to this question and the result has not been overcome.

I haven't read questions about question F yet. During the superbin competition, I had all questions about the AC, and I had a good time to worship. It is reported that question F is not difficult, but the question is quite long.

Paste the Settlers of Catan code:

Code

  # Include  <  Stdio. h  >  
# Include < Stdlib. h >
# Include < String . H >
Int Map [ 30 ] [ 30 ], Max, N;
Bool Visit [ 3000 ];
Int Make ( Int ID, Int I)
{
If (ID > I) Return ID + I * 100 ;
Else Return ID * 100 + I;
}
Void DFS ( Int ID, Int M)
{
If (M > Max) max = M;
Int I;
For (I = 0 ; I < N; I ++ ){
If (ID ! = I && Map [ID] [I] = 1 && Visit [make (ID, I)] = False ){
Visit [make (ID, I)] = True ;
DFS (I, m + 1 );
Visit [make (ID, I)] = False ;
}
}
}
Int Main ()
{
Int T, I, X, Y;

While (Scanf ( " % D " , & N, & T) && N + T)
{
Memset (map, 0 , Sizeof (MAP ));
For (I = 0 ; I < T; I ++ ){
Scanf ( " % D " , & X, & Y );
Map [x] [Y] = Map [y] [x] = 1 ;
}
Max = 0 ;
For (I = 0 ; I < N; I ++ )
DFS (I, 0 );
Printf ( " % D \ n " , Max );
}
Return 0 ;
}

 

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.