[AtCoder Beginner Contest 165] E - Rotation Matching (构造)
Problem Statement
You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.) NN players will participate in this competition, and they are given distinct integers from 11 through NN. The arena has MM playing fields for two players. You need to assign each playing field two distinct integers between 11 and NN (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of NN rounds, each of which proceeds as follows:
- For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.
- Then, each player adds 11 to its integer. If it becomes N+1N+1, change it to 11.
You want to ensure that no player fights the same opponent more than once during the NN rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
题意:
大概就是给定一个含有\(\mathit n\)个整数(\(1,2,3,\dots,n-1,n\))环,
让你在其中选择\(\mathit m\)对数字,要求:
1、 每一个数字最多出现在一个数字对中。
2、不能有两个数字对,使其在环的2个方向的距离有相等的。
思路:
当\(\mathit m\)为奇数时:
当\(\mathit m\)为偶数时:
即:
我们可以构造\((1,m+1),(2,m),...\)差为\(m,m-2,m-4...\)
\((m+2,2*m+1),(m+3,2*m),...\)差为\(m-1,m-3...\)
代码:
int n = readint();
int k = readint();
int base = k;
int l = 1;
int r = k + 1;
while (base--)
{
if (l >= r)
{
l = k + 2;
r = 2 * k + 1;
}
printf("%d %d\n", l++, r-- );
}