题目链接:http://codeforces.com/problemset/problem/417/C
题目大意:所有参加者被分成n个小组,两支球队只能打一次。构造出每个队击败其他球队恰好k次的情况。
题目分析:
以 5 2来说:
Input
5 2
Output
10
1 2
1 3//bi为ai+1开始的往后k个
2 3
2 4
3 4
3 5
4 5
4 1//此处的1可以看做是 6 % 5 = 1
5 1//此处的1可以看做是6 % 5 = 1
5 2//此处的2可以看做是7 % 5 = 2
代码参考:
#include<set>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1009;
set<int>link[N];
int edge[N][N];
int main()
{
int n, x, k, i, j;
while (~scanf("%d%d", &n, &k)) {
if (n <= 2 * k) {
puts("-1");
} else {
printf("%d\n", n * k);
for (i = 1; i <= n; ++i) {
x = 0;//记录已配对几个
for (j = i+1; j <= 2*n; ++j) {
x++;
printf("%d %d\n", i, j % n == 0 ? n : j % n);
if (x == k) {
break;
}
}
}
}
}
return 0;
}