Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 700700 points
Problem Statement
You are given an integer NN. Build an undirected graph with NN vertices with indices 11 to NN that satisfies the following two conditions:
- The graph is simple and connected.
- There exists an integer SS such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is SS.
It can be proved that at least one such graph exists under the constraints of this problem.
Constraints
- All values in input are integers.
- 3≤N≤1003≤N≤100
Input
Input is given from Standard Input in the following format:
NN
Output
In the first line, print the number of edges, MM, in the graph you made. In the ii-th of the following MM lines, print two integers aiai and bibi, representing the endpoints of the ii-th edge.
The output will be judged correct if the graph satisfies the conditions.
Sample Input 1 Copy
3
Sample Output 1 Copy
21 32 3
- For every vertex, the sum of the indices of the vertices adjacent to that vertex is 33.
题意:
给你一个数字n,
让你构造你简单图(无重边)
要求这个图的每一个节点所连接的节点的id值加起来相等。*(不用加自己的id值)
思路:
显然找规律的构造题。
我们反过来想,先构建一个完全图,设法去掉一些有规律的边,使整个图满足条件。
通过分析可以发现规律。
当n是奇数的时候,
删除i+j=n的边
否则
删除i+j=n+1的边
细节见代码:
#include#include #include #include #include #include #include #include