Yet Another Ball Problem
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 bibi be the color of the man's costume and gigi 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,…,bnb1,b2,…,bn and g1,g2,…gng1,g2,…gn ) in such a way that:

  1. for every ii : bibi and gigi 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≠j ) such that bi=bjbi=bj and gi=gjgi=gj 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≠gibi≠gi 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+1bi≠bi+1 and gi≠gi+1gi≠gi+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.

Input

The only line of the input contains two integers nn and kk (2≤n,k≤2⋅1052≤n,k≤2⋅105 ) — the number of pairs and the number of colors.

Output

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 bibi and gigi — 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.

Examples
Input

Copy
4 3
Output

Copy
YES
3 1
1 3
3 2
2 3
Input

Copy
10 4
Output

Copy
YES
2 1
1 3
4 2
3 4
4 3
3 2
2 4
4 1
1 4
3 1
Input

Copy
13 4
Output

Copy
NO
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
ll n,k;
cin>>n>>k;
if(n>k*(k-)) cout<<"NO\n"<<endl;
else{
cout<<"YES\n"<<endl;
int cnt=;
for( ll i=; i<=k; i++ ){
for( ll j=i+; j<=k; j++ ){
cout<<i<<" "<<j<<endl;
cnt++;
if(cnt>=n) return ;
cout<<j<<" "<<i<<endl;
cnt++;
if(cnt>=n) return ;
}
}
}
return ;
}

Yet Another Ball Problem的更多相关文章

  1. Yet Another Ball Problem CodeForces - 1118E (简单构造)

    大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...

  2. HDU 4362 Dragon Ball 贪心DP

    Dragon Ball Problem Description   Sean has got a Treasure map which shows when and where the dragon ...

  3. SK-Learn使用NMF(非负矩阵分解)和LDA(隐含狄利克雷分布)进行话题抽取

    英文链接:http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html 这 ...

  4. [转]"Windows Phone 7程序设计”完全版电子书可以免费下载了

    本文转自:http://www.cnblogs.com/salam/archive/2010/10/29/1864246.html 现在学习Windows Phone 7开发资料十分有限,除了MSDN ...

  5. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  6. Latency Compensating Methods in Client/Server In-game Protocol Design and Optimization【转】

    https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Proto ...

  7. Dragon Ball--hdoj

    Dragon Ball Problem Description Five hundred years later, the number of dragon balls will increase u ...

  8. 【补题记录】ZJU-ICPC Summer Training 2020 部分补题记录

    补题地址:https://zjusummer.contest.codeforces.com/ Contents ZJU-ICPC Summer 2020 Contest 1 by Group A Pr ...

  9. 2016北京集训测试赛(十六)Problem C: ball

    Solution 这是一道好题. 考虑球体的体积是怎么计算的: 我们令\(f_k(r)\)表示\(x\)维单位球的体积, 则 \[ f_k(1) = \int_{-1}^1 f_{k - 1}(\sq ...

随机推荐

  1. [DevExpress使用随笔]之NavBarControl控件(一)【转】

    https://blog.csdn.net/HXC_HUANG/article/details/78614092 NavBarControl是具有可扩展组的侧导航控件.一.在Winform窗口中拖入N ...

  2. linux下gflags的安装

    gflags是google开发的一套命令行参数解析工具,被很多软件系统所依赖,应该算是一个基础的库,安装其实很简单,但是如果在网上找的一些教程大部分都是安装后不能被其他软件调用的,因为默认使用cmak ...

  3. Initialize a vector in C++ (5 different ways)

    https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/ Following are different way ...

  4. WPF双向数据绑定总结

    参考官方:https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/data/data-binding-wpf 实例程序:https://files. ...

  5. [Oracle] “表中有数据,但select count(*)的结果为0”问题的解决办法

    一.问题 今天遇到了一个神奇的问题--表中有数据,但select count(*)的结果为0. 这个问题最初的表现形式是"查询报表没有分页". 最开始还以为是java端的问题.后来 ...

  6. TRAC-IK机器人运动学求解器

    TRAC-IK和Orocos KDL类似,也是一种基于数值解的机器人运动学求解器,但是在算法层面上进行了很多改进(Specifically, KDL’s convergence algorithms ...

  7. LNAMP服务器环境(源码安装)

    在安装前先看下它们安装时所需要的依赖库:http://www.cnblogs.com/fps2tao/p/7699448.html 1.nginx源码安装 下载:http://nginx.org/en ...

  8. 框架Thinkphp5 简单的实现行为 钩子 Hook

    这篇文章主要介绍了关于框架Thinkphp5 简单的实现行为 钩子 Hook,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 实现在一个方法开始和结束加入两个行为:api_init.ap ...

  9. 原创科幻短篇《Bug》

    这回不是纯科幻,夹了点玄幻. 以下正文: 大一的时候,李双休谈了个女朋友,俩人学校相距不远,周末约一起看电影.那是李双休第一次自己坐公交,坐反了,绕城一周,电影开始后一个小时才到,就赶上看了个片尾彩蛋 ...

  10. 4 Git 基础 - 撤消操作

    撤消操作 任何时候,你都有可能需要撤消刚才所做的某些操作.接下来,我们会介绍一些基本的撤消操作相关的命令.请注意,有些撤销操作是不可逆的,所以请务必谨慎小心,一旦失误,就有可能丢失部分工作成果. 修改 ...