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 ...
随机推荐
- [Web 前端] VML、SVG、Canvas简介
1.VML: VML的全称是Vector Markup Language(矢量可标记语言),矢量的图形,意味着图形可以任意放大缩小而不损失图形的质量,这在制作地图上有很大用途,VML只是被IE支持. ...
- angularjs自定义filter
angular.Module API Overview Methods info([info]); provider(name, providerType); factory(name, provid ...
- [dubbo] Dubbo API 笔记——配置参考
schema 配置参考 所有配置项分为三大类 服务发现:表示该配置项用于服务的注册与发现,目的是让消费方找到提供方 服务治理:表示该配置项用于治理服务间的关系,或为开发测试提供便利条件 性能调优:表示 ...
- RobotFrameWork接口项目分层及通用控制方式
1. 前言 上一篇文章介绍了在设计接口用例之前应遵守的设计规范,详见<RobotFramework接口设计规范>,当然读者公司的内部规范也不一定非得完全遵循笔者所提到的,适合自己公司内部的 ...
- 30天自制操作系统 - 来一个hello world
helloos.nas 源码: ; hello-os ; TAB= ; 以下这段是标准的FAT12格式软盘专用代码 DB 0xeb, 0x4e, 0x90 DB "HELLOIPL" ...
- MySQL processlist中需要关注的状态
一般而言,我们在processlist结果中如果经常能看到某些SQL的话,至少可以说明这些SQL的频率很高,通常需要对这些SQL进行进一步优化. 今天我们要说的是,在processlist中,看到哪些 ...
- 抽奖活动 mark
).prizeName().remainingPrize().prizeRate().prizeName().remainingPrize().prizeRate().prizeName().rema ...
- Navicat Premium 12破解方法
来源网址:https://www.jianshu.com/p/42a33b0dda9c 1.按步骤安装Navicat Premium,如果没有可以去官网下载:http://www.navicat.co ...
- NetCore指令集和
1.查看当前目录的版本号 C:\Users\Administrator>dotnet --version 1.0.4 2.发布程式,进入到指定目录 dotnet publish 3.运行程式 # ...
- Linux命令行增强版
0. 前言 周末大早上的,没事做,了解下这几个命令了,哎~~~. 正常情况下,Linux下的命令行,界面比较丑,命令行命令有时候也不是很友好,下面就通过这几个命令或工具,美化一下命令行. 1. oh- ...