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:
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:
Good color choosing:
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
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 int main(int argc, char const *argv[]) 5 { 6 ll n,k; 7 cin>>n>>k; 8 if(n>k*(k-1)) cout<<"NO\n"<<endl; 9 else{ 10 cout<<"YES\n"<<endl; 11 int cnt=0; 12 for( ll i=1; i<=k; i++ ){ 13 for( ll j=i+1; j<=k; j++ ){ 14 cout<<i<<" "<<j<<endl; 15 cnt++; 16 if(cnt>=n) return 0; 17 cout<<j<<" "<<i<<endl; 18 cnt++; 19 if(cnt>=n) return 0; 20 } 21 } 22 } 23 return 0; 24 }
原文:https://www.cnblogs.com/Bravewtz/p/10466309.html