• 2020牛客暑期多校训练营(第三场)D.Points Construction Problem 构造


    https://ac.nowcoder.com/acm/contest/5668/D

    出题人题解如下:(比较懒,不想写了

     

     

     

     

     

     代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN=300;
    const int SIZE=3e5+5;
    const long long mod=998244353;
    typedef long long ll;
    //typedef __int128 LL;
    const int inf=0x3f3f3f3f;
    const long long INF=0x3f3f3f3f3f3f3f3f;
    int g[205][205];
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            memset(g,0,sizeof g);
            int n,m;
            scanf("%d%d",&n,&m);
            int flag=0;
            int minn=inf;
            int a,b;
            if(m%2)flag=1;
            if(m>4*n)flag=1;
            
            int tmp=sqrt(n);
            if(tmp*tmp==n)a=tmp,b=tmp,minn=2*(tmp+tmp);
            else if(tmp*(tmp+1)>=n)a=tmp,b=tmp+1,minn=2*(tmp+tmp+1);
            else
            {
                a=tmp+1;
                b=a;
                minn=2*(tmp+1+tmp+1);
            }
            /*for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(i*j>=n&&2*(i+j)<minn)
                    {
                        a=i;
                        b=j;
                        minn=2*(i+j);
                    }
                }
            }*/
            if(m<minn)flag=1;
            if(flag==1)
            {
                printf("No
    ");
                continue;
            }
            printf("Yes
    ");
            int id=55,cnt=0;
            for(int i=1;i<=a;i++)
            {
                for(int j=1;j<=b;j++)
                {
                    if(cnt==n)break;
                    g[i][j]=1;
                    cnt++;
                }
            }
            for(int i=1;i<=a;i++)
            {
                for(int j=1;j<=b;j++)
                {
                    if(m>minn)
                    {
                        if(g[i][j+1]==0)minn-=2;
                        if(g[i+1][j]==0)minn-=2;
    
                        g[i][j]=0,g[id][id]=1,id++,minn+=4;
    
                    }
                    else break;
                }
            }
            if(minn>m)
            {
                if(g[id-2][id-2]==0)g[id-1][id-1]=0,g[a+1][1]=1;
                else g[id-1][id-1]=0,g[id-2][id-1]=1;
            }
            for(int i=1;i<=200;i++)
            {
                for(int j=1;j<=200;j++)
                {
                    if(g[i][j])printf("%d %d
    ",i,j);
                }
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    OpenGL入门1.3:着色器 GLSL
    OpenGL入门1.2:渲染管线简介,画三角形
    C++回调,函数指针
    JavaScript 比较和逻辑运算符
    JS 运算符
    JS 函数
    JS 对象
    JS 数据类型
    JS 变量
    JS 注释
  • 原文地址:https://www.cnblogs.com/MZRONG/p/13347668.html
Copyright © 2020-2023  润新知