Time Limit: 2 sec / Memory Limit: 1024 MB

Score : <var>700700</var> points

Problem Statement

You are given an integer <var>NN</var>. Build an undirected graph with <var>NN</var> vertices with indices <var>11</var> to <var>NN</var> that satisfies the following two conditions:

  • The graph is simple and connected.
  • There exists an integer <var>SS</var> such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is <var>SS</var>.

It can be proved that at least one such graph exists under the constraints of this problem.

Constraints

  • All values in input are integers.
  • <var>3N1003≤N≤100</var>

Input

Input is given from Standard Input in the following format:

<var>NN</var>

Output

In the first line, print the number of edges, <var>MM</var>, in the graph you made. In the <var>ii</var>-th of the following <var>MM</var> lines, print two integers <var>aiai</var> and <var>bibi</var>, representing the endpoints of the <var>ii</var>-th edge.

The output will be judged correct if the graph satisfies the conditions.


Sample Input 1 Copy

Copy
3

Sample Output 1 Copy

Copy
2
1 3
2 3
  • For every vertex, the sum of the indices of the vertices adjacent to that vertex is <var>33</var>.

 

题意:

给你一个数字n,

让你构造你简单图(无重边)

要求这个图的每一个节点所连接的节点的id值加起来相等。*(不用加自己的id值)

思路:

显然找规律的构造题。

我们反过来想,先构建一个完全图,设法去掉一些有规律的边,使整个图满足条件。

通过分析可以发现规律。

当n是奇数的时候,

删除i+j=n的边

否则

删除i+j=n+1的边

 

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    int n;
    cin>>n;
    std::vector<pii> v;
    int ans=0;
    repd(i,1,n)
    {
        repd(j,i+1,n)
        {
            if(n&1)
            {
                if(i+j!=n)
                {
                    ans++;
                    v.push_back(mp(i,j));
                    // cout<<i<<" "<<j<<endl;
                }
            }else
            {
                if(i+j!=n+1)
                {
                    ans++;
                    v.push_back(mp(i,j));
                    // cout<<i<<" "<<j<<endl;
                }
            }
        }
    }
    cout<<ans<<endl;
    for(auto x: v)
    {
        cout<<x.fi<<" "<<x.se<<endl;
    }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}