CF1118E.Yet Another Ball Problem

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The king of Berland organizes a ball! nn pair are invited to the ball, they are numbered from 11 to nn. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from 11 to kk, inclusive.

Let bib_i be the color of the man's costume and gig_i be the color of the woman's costume in the ii-th pair. You have to choose a color for each dancer's costume (i.e. values b1,b2,…,bnb_1, b_2, \dots, b_n and g1,g2,…gng_1, g_2, \dots g_n) in such a way that:

  1. for every ii: bib_i and gig_i are integers between 11 and kk, inclusive;
  2. there are no two completely identical pairs, i.e. no two indices i,ji, j (i≠ji \ne j) such that bi=bjb_i = b_j and gi=gjg_i = g_j at the same time;
  3. there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. bi≠gib_i \ne g_i for every ii;
  4. for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every ii from 11 to n−1n-1 the conditions bi≠bi+1b_i \ne b_{i + 1} and gi≠gi+1g_i \ne g_{i + 1} hold.

Let's take a look at the examples of bad and good color choosing (for n=4n=4 and k=3k=3, man is the first in a pair and woman is the second):

Bad color choosing:

  • (1,2)(1, 2), (2,3)(2, 3), (3,2)(3, 2), (1,2)(1, 2) — contradiction with the second rule (there are equal pairs);
  • (2,3)(2, 3), (1,1)(1, 1), (3,2)(3, 2), (1,3)(1, 3) — contradiction with the third rule (there is a pair with costumes of the same color);
  • (1,2)(1, 2), (2,3)(2, 3), (1,3)(1, 3), (2,1)(2, 1) — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same).

Good color choosing:

  • (1,2)(1, 2), (2,1)(2, 1), (1,3)(1, 3), (3,1)(3, 1);
  • (1,2)(1, 2), (3,1)(3, 1), (2,3)(2, 3), (3,2)(3, 2);
  • (3,1)(3, 1), (1,2)(1, 2), (2,3)(2, 3), (3,2)(3, 2).

You have to find any suitable color choosing or say that no suitable choosing exists.

贝尔兰王国的国王正在举办一场舞会!共有 nn 对舞者受邀参加舞会,编号为 11 至 nn。每对舞者由一名男性和一名女性组成。每位舞者(无论男女)都身着单色服装,每套服装的颜色用一个介于 11 到 kk(含端点)之间的整数表示。

设第 ii 对中男性的服装颜色为 bib_i,女性的服装颜色为 gig_i。你需要为每位舞者的服装选定一种颜色(即确定值 b1,b2,…,bnb_1, b_2, \dots, b_n 和 g1,g2,…,gng_1, g_2, \dots, g_n),使得满足以下全部条件:

  1. 对每个 ii:bib_i 和 gig_i 均为介于 11 到 kk(含端点)之间的整数;
  2. 不存在两对完全相同的舞者组合,即不存在两个下标 i,ji, j(i≠ji \ne j),使得同时满足 bi=bjb_i = b_j 且 gi=gjg_i = g_j;
  3. 不存在某对舞者中男女服装颜色相同的情况,即对每个 ii 都有 bi≠gib_i \ne g_i;
  4. 对任意两个相邻(连续)的舞者对,其男性服装颜色互不相同,且女性服装颜色也互不相同;即对每个 i=1,2,…,n−1i = 1, 2, \dots, n-1,均满足 bi≠bi+1b_i \ne b_{i + 1} 且 gi≠gi+1g_i \ne g_{i + 1}。

我们来看一些颜色分配方案的正反示例(其中 n=4n=4、k=3k=3,每对中男性在前、女性在后):

不合法的颜色分配方案(Bad color choosing):

  • (1,2)(1, 2), (2,3)(2, 3), (3,2)(3, 2), (1,2)(1, 2) — 违反第 2 条规则(存在完全相同的舞者对);
  • (2,3)(2, 3), (1,1)(1, 1), (3,2)(3, 2), (1,3)(1, 3) — 违反第 3 条规则(存在一对男女服装颜色相同);
  • (1,2)(1, 2), (2,3)(2, 3), (1,3)(1, 3), (2,1)(2, 1) — 违反第 4 条规则(存在两个相邻舞者对,其男性/女性服装颜色之一相同)。

合法的颜色分配方案(Good color choosing):

  • (1,2)(1, 2), (2,1)(2, 1), (1,3)(1, 3), (3,1)(3, 1);
  • (1,2)(1, 2), (3,1)(3, 1), (2,3)(2, 3), (3,2)(3, 2);
  • (3,1)(3, 1), (1,2)(1, 2), (2,3)(2, 3), (3,2)(3, 2)。

你需要找出任意一种满足上述条件的颜色分配方案;若不存在这样的方案,则输出说明无解。

输入格式

The only line of the input contains two integers nn and kk (2≤n,k≤2⋅1052 \le n, k \le 2 \cdot 10^5) — the number of pairs and the number of colors.

输入仅有一行,包含两个整数 nn 和 kk(2≤n,k≤2⋅1052 \le n, k \le 2 \cdot 10^5),分别表示数对的个数和颜色的种数。

输出格式

If it is impossible to find any suitable colors choosing, print "NO".

Otherwise print "YES" and then the colors of the costumes of pairs in the next nn lines. The ii-th line should contain two integers bib_i and gig_i — colors of costumes of man and woman in the ii-th pair, respectively.

You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

如果无法找到任何合适的颜色选择方案,则输出 "NO"。

否则,先输出 "YES",然后在接下来的 nn 行中输出各对伴侣的服装颜色。第 ii 行应包含两个整数 bib_i 和 gig_i,分别表示第 ii 对中男性和女性的服装颜色。

每个字母可使用任意大小写(大写或小写)。例如,"YeS"、"no" 和 "yES" 均可接受。

输入输出样例

  • 输入#1

    4 3

    输出#1

    YES
    3 1
    1 3
    3 2
    2 3
  • 输入#2

    10 4

    输出#2

    YES
    2 1
    1 3
    4 2
    3 4
    4 3
    3 2
    2 4
    4 1
    1 4
    3 1
  • 输入#3

    13 4

    输出#3

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页