Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3328
Surface:
Wu Xing Time limit: 1 Second Memory Limit: 32768 KB
Introduction
The Wu Xing, or the Five movements, Five phases or Five steps/stages, is chiefly an ancient mnemonic device, in many trad Itional Chinese fields.
The doctrine of five phases describes, cycles, a generating or creation cycle, also known as "Mother-son", and an OVERC Oming or destruction cycle, also known as "Grandfather-nephew", of interactions between the phases.
Generating:
- Wood feeds fire;
- Fire creates Earth (ASH);
- Earth Bears Metal;
- Metal carries water (as in a bucket or taps, or water condenses on Metal);
- Water nourishes Wood.
Overcoming:
- Wood Parts Earth (such as roots) (or Trees can prevent soil erosion);
- Earth absorbs (or muddies) water (or earth Dam control the water);
- Water quenches fire;
- Fire melts Metal;
- Metal chops Wood.
With the both types of interactions in the above graph, any of the nodes is connected by an edge.
Problem
In a-graph with N -nodes, to ensure. Any, nodes is connected by at least one edge, how many types of inter Actions is required at least? Here a type of interaction should has the following properties:
- It can be represented as a set of directed edges in the graph.
- For each type of interaction, there should is one and only one edge starting at each node.
- For each type of interaction, there should is one and only one edge ending at each node.
- The interactions is made up of cycles, i.e. starting from a arbitrary node and following the edges with the SAM E Type of interaction, you can always reach the starting node after several steps.
Input
For each test case, there's a line with an integer N (3 <= N < 1,000,000), the number of nodes in The graph.
N= 0 Indicates the end of input.
Output
For each test case, the output a line with the number of interactions is required at least.
Sample Input
50
Sample Output
2
Reference
Http://en.wikipedia.org/wiki/Wu_Xing
Test instructions
With how many kinds of circle relationship, you can make any two sides can directly connect an edge.
Solving:
At the beginning to see this problem is more dizzy bar, carefully read the question, found that the topic is very simple, is to ask how many kinds of circle relationship, can make any two points can be connected to an edge. A relationship, for example, allows 1 points to establish a relationship with two other points. Therefore, it can be concluded that the number of relationships required is N/2.
Code:
ZOJ 3328 wuxing