标签:构造
题目大意:
分析:
AC code:
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#define pb push_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;
void open_init()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
}
void close_file()
{
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
}
const int MAXN = 2009;
int n, ans;
int g[MAXN][MAXN];
int main()
{
open_init();
scanf("%d", &n);
if(n > 1) ans = n-(n&1^1);
else ans = 0;
rep(i, 1, ans)
rep(j, i+1, ans)
g[i][j] = g[j][i] = (i+j)%ans+1;
rep(i, ans+1, n)
rep(j, 1, n-1)
g[i][j] = g[j][i] = (j<<1)%ans+1;
printf("%d\n", ans);
rep(i, 1, n)
{
rep(j, 1, n-1)
printf("%d ", g[i][j]);
printf("%d\n", g[i][n]);
}
close_file();
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
sgu288:Best Tournament Schedule(构造)
标签:构造
原文地址:http://blog.csdn.net/qq_20118433/article/details/46942985