题解:CF1118E Yet Another Ball Problem

· · 题解

题目理解:

AC 代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k;
    cin>>n>>k;
    long long int sum=k*(k-1);
    if(n>sum)
    {
        cout<<"NO";
        return 0;
    }
    int cnt=0;
    int p=1;
    cout<<"YES"<<endl;
    int u=0;
    for(int i=k;i>=1;i--)
    {

        for(int j=k-i+2;j<=k;j++)
        {
            cout<<p<<" "<<j;
            cout<<endl;
            cout<<j<<" "<<p;
            cout<<endl;
            cnt+=2;
            u=j+1;
            if(cnt+1>=n)
            {
                break;
            }
        }
        if(cnt+1>=n)
        {
            break;
        }
        p++;
    }
    if(n%2==1)
    {
        if(u==k+1)
        {
            p++;
            u=k-(k-p+1)+2;
        }
        cout<<p<<" "<<u;
    }
    return 0;
} 

AC 记录

这个蒟蒻码风真丑。