Introduction
The Wu Xing, or the Five Movements, Five Phases or Five Steps/Stages, are chiefly an ancient mnemonic device, in many traditional Chinese fields.
The doctrine of five phases describes two cycles, a generating or creation cycle, also known as "mother-son", and an overcoming 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 tap, 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 two types of interactions in the above graph, any two nodes are connected by an edge.
Problem
In a graph with N nodes, to ensure that any two nodes are connected by at least one edge, how many types of interactions are required at least? Here a type of interaction should have the following properties:
- It can be represented as a set of directed edges in the graph.
- For each type of interaction, there should be one and only one edge starting at each node.
- For each type of interaction, there should be one and only one edge ending at each node.
- The interactions are made up of cycles, i.e. starting from an arbitrary node and following the edges with the same 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, output a line with the number of interactions that are required at least.
Sample Input
5 0
Sample Output
2
Reference
http://en.wikipedia.org/wiki/Wu_Xing
题意:
一个包含N个节点的图,为了确保任意两点都至少有一条边相连,问至少需要多少种相互作用关系。
相互作用关系,包含以下几种属性:
1. 可以表示为图中的有向边。
2. 对于每个点有且仅有一条开始边和结束边。
3. 这种关系最终形成环。
例如五行就是图上的五个点借助相生相克两种相互作用关系而满足要求。
题解:总共有n*(n-1)/2条边,那么就是(n-1)/2个环。
当n%2==1 答案就是n/2
当n%2==0 剩余的边要自成环 答案是(n-1)/2+1 等于n/2。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(i=a;i<=b;i++)
#define per(i,a,b) for(i=a;i>=b;i--)
int main(){
int n;
while(scanf("%d",&n)&&n)printf("%d\n",n/2);
return 0;
}