Yet Another Ball Problem
3 seconds
256 megabytes
standard input
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:
- for every ii : bibi and gigi are integers between 11 and kk , inclusive;
- 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;
- 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 ;
- 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.
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.
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.
4 3
YES
3 1
1 3
3 2
2 3
10 4
YES
2 1
1 3
4 2
3 4
4 3
3 2
2 4
4 1
1 4
3 1
13 4
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的更多相关文章
- Yet Another Ball Problem CodeForces - 1118E (简单构造)
大意: 求构造n个pair, 每个pair满足 对于每k组, 让$b_i$为$[1,k]$, $g_i$循环右移就好了 int n, k, cnt; int main() { scanf(" ...
- HDU 4362 Dragon Ball 贪心DP
Dragon Ball Problem Description Sean has got a Treasure map which shows when and where the dragon ...
- SK-Learn使用NMF(非负矩阵分解)和LDA(隐含狄利克雷分布)进行话题抽取
英文链接:http://scikit-learn.org/stable/auto_examples/applications/topics_extraction_with_nmf_lda.html 这 ...
- [转]"Windows Phone 7程序设计”完全版电子书可以免费下载了
本文转自:http://www.cnblogs.com/salam/archive/2010/10/29/1864246.html 现在学习Windows Phone 7开发资料十分有限,除了MSDN ...
- 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> ...
- 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 ...
- Dragon Ball--hdoj
Dragon Ball Problem Description Five hundred years later, the number of dragon balls will increase u ...
- 【补题记录】ZJU-ICPC Summer Training 2020 部分补题记录
补题地址:https://zjusummer.contest.codeforces.com/ Contents ZJU-ICPC Summer 2020 Contest 1 by Group A Pr ...
- 2016北京集训测试赛(十六)Problem C: ball
Solution 这是一道好题. 考虑球体的体积是怎么计算的: 我们令\(f_k(r)\)表示\(x\)维单位球的体积, 则 \[ f_k(1) = \int_{-1}^1 f_{k - 1}(\sq ...
随机推荐
- javacript onclick事件中传递对象参数
var user = {id:1, name:'zs', age:20}; var ele = '<a onclick="edit(' + JSON.stringify(user).r ...
- iOS:解决UITextView自适应高度粘贴大量文字导致显示不全的问题
一.描述 在UITextView输入框中粘贴大量的文字时,UITextView内容自适应高度计算出现误差,导致整块文字上移消失. 二.方案 在UITextView文字改变的监听中添加如下方法即可. [ ...
- 关闭pycharm自动更新
如下图:
- CentOS 7 安装 Oracle 11.2.0.4
一.安装环境 CentOS Linux release 7.2.1511 (Core) Oracle Database 11g Release 2 (11.2.0.4) 二.安装前准备 2.1 修改主 ...
- [转]epoll详解
什么是epollepoll是什么?按照man手册的说法:是为处理大批量句柄而作了改进的poll.当然,这不是2.6内核才有的,它是在2.5.44内核中被引进的(epoll(4) is a new AP ...
- jquery裁剪图片插件cropit示例
重装农药第16天!! jquery裁剪图片插件cropit示例 背景:做的手机网页项目,用html file控件上传图片,有些手机拍照后图片会很大,20M以上的,用之前的H5 formdata上传的话 ...
- easyui中combobox 取值
<input id="cmbstrTrainType" class="easyui-combobox" name="cmbstrTrainTyp ...
- nmon监控
原文:https://www.cnblogs.com/wnfindbug/p/5719181.html 一.检查安装环境 # uname –a (查看操作系统信息,所检查服务器为64位操作系统) Li ...
- idea当配置eclipse快捷键时,全局替换的快捷键是什么?
简介 每次为了新版本新建一个分支的时候,都要改每个maven的版本号,好麻烦,有么有?如下图: 当idea配置eclipse快捷键时,默认是没有全局替换快捷键的,需要设置 步骤 首先打开setti ...
- 【RPC】手撸一个简单的RPC框架实现
涉及技术 序列化.Socket通信.Java动态代理技术,反射机制 角色 1.服务提供者:运行在服务端,是真实的服务实现类 2.服务发布监听者:运行在RPC服务端,1将服务端提供的 ...