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 ...
随机推荐
- MediaInfo代码阅读
MediaInfo是一个用来分析媒体文件的开源工具. 支持的文件非常全面,基本上支持所有的媒体文件. 最近是在做HEVC开发,所以比较关注MediaInfo中关于HEVC的分析与处理. 从Meid ...
- 【黑魔法】Covering Indexes、STRAIGHT_JOIN
今天给大家介绍两个黑魔法,这都是压箱底的法宝.大家在使用时,一定要弄清他们的适用场景及用法,用好了,就是一把开天斧,用不好那就是画蛇添足.自从看过耗子哥(左耳朵耗子)的博客,都会给对相应专题有兴趣的小 ...
- Redis具体解释
redis 学习指南 一.介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.一个高性能的key-value数据库.并提供多种语言的API.说到Key-Val ...
- 利用StringEscapeUtils来转义和反转义html/xml/javascript中的特殊字符
我们经常遇到html或者xml在Java程序中被某些库转义成了特殊字符. 例如: 各种逻辑运算符: > >= < <= == 被转义成了 == ...
- 设置mysql 事务锁超时时间 innodb_lock_wait_timeout
Mysql数据库采用InnoDB模式,默认参数:innodb_lock_wait_timeout设置锁等待的时间是50s,一旦数据库锁超过这个时间就会报错. mysql> SHOW GLOBAL ...
- android学习十二(android的Content Provider(内容提供器)的使用)
文件存储和SharePreference存储以及数据存储一般为了安全,最好用于当前应用程序中訪问和存储数据.内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能 ...
- Navicat Win 和 Mac 视图类快捷键对比
Navicat 查询是根据用户需求从数据库提取可读格式的数据,Navicat 提供两个强大的工具与 SQL 查询工作:查询创建工具和查询编辑器,查询创建工具可视觉化地创建查询,查询编辑器可直接编辑查询 ...
- Android Studio打包过程和应用安装过程
三个部分,检查项目和读取基本配置,Gradle Build,Apk Install和LaunchActivity. 应用安装到手机,会复制APK安装包到data/app目录下,解压并扫描安装包,把de ...
- windows下查看特定端口被什么程序占用
我电脑上因为命令: netstat -ano 列出的太多了,所以不好看. 以下是其他方式: 查看8088端口占用情况: 开始---->运行---->cmd,或者是window+R组合键,调 ...
- 【转】WPF 与 WinForm 间的按键值(枚举)转换
There is a function for that in System.Windows.Input.KeyInterop static class. Try:var inputKey = Key ...