首先可以算出无解的充分不必要条件,所有边的和为sum=3*((n-1)*n)/2,如果sum%n!=0显然无解。
也就是说n为奇数必然无解。现在考虑n为偶数的情况。
不妨假设n为偶数有解,现在考虑如何将这个解构造出来。
设此时n边形的为2*k+1,那么也就说,内边的每相邻两个边的和要为{k+2....3*k+2}
把边构造成这个样子即可。
k+1 1 k+2 2 k+3......2*k+1.
另外这个oj的读入效率真是感人肺腑啊。。。
# include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # include <bitset> # include <set> # include <cmath> # include <algorithm> using namespace std; # define lowbit(x) ((x)&(-x)) # define pi acos(-1.0) # define eps 1e-8 # define MOD 1000000007 # define INF 1000000000 # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define FO(i,a,n) for(int i=a; i<n; ++i) # define bug puts("H"); # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mp make_pair # define pb push_back typedef pair<int,int> PII; typedef vector<int> VI; # pragma comment(linker, "/STACK:1024000000,1024000000") typedef long long LL; inline int Scan() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void Out(int a) { if(a<0) {putchar('-'); a=-a;} if(a>=10) Out(a/10); putchar(a%10+'0'); } const int N=105; //Code begin... int main () { int n; scanf("%d",&n); if (n&1) {puts("0"); return 0;} int k=(n-1)/2; for (int i=n-1; i>=1; --i) Out(i), putchar(' '); putchar('\n'); for (int i=k+1; i<2*k+1; ++i) Out(i), putchar(' '), Out(i-k), putchar(' '); Out(2*k+1); putchar('\n'); return 0; }