• AGC006_B Median Pyramid Easy


    图片搬运来源:官方

    题面翻译
    有一个n层的金字塔,从上往下数第i层有2*i-1个格子,呈中心对齐状。对于金字塔上的每个格子填的数(不包括第n层上的),它等于下面一层的对应位置上和向左一格的位置上,以及向右一格的位置上的三个数的中位数。那么当我们确定第n层上的数时,整个金字塔每个位置上的数也就确定了。如下图:

    给定第一层的格子上的数,构造一种第n层的填数方案满足此
    条件。

    思路
    手玩好题呀。
    对于金字塔的某一层,如果存在某两个相邻的格子上填了相同的数,那么这两个格子向上所有对应的位置上都会是这个数,如下图:

    那么就很好构造了。我们只要满足第n-1层中心线与其向右一格的位置上均为给定的数,其余的位置随便填就行。至于具体细节可以自己思考一下,或者详见代码。

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn=1e5;
    int n,x;
    int a[maxn*2+8];
    
    int read()
    {
        int x=0,f=1;char ch=getchar();
        for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
        for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
        return x*f;
    }
    
    int main()
    {
        n=read(),x=read();
        if (x==1||x==2*n-1)
    	{
    	    puts("No");
    	    return 0;
    	}
        if (n==2)
    	{
    	    puts("Yes");
    	    puts("1 2 3");
    	    return 0;
    	}
        a[n]=x;
        if (x==2)
    	{
    	    a[n-1]=x+1,a[n+1]=x-1,a[n+2]=x+2;
    	    int now=1;
    	    for (int i=1;i<n-1;i++)
    		{
    		    if (now==x-1) now=x+3;
    		    a[i]=now++;
    		}
    	    for (int i=n+3;i<2*n;i++)
    		{
    		    if (now==x-1) now=x+3;
    		    a[i]=now++;
    		}
    	}
        else
    	{
    	    a[n-1]=x-1,a[n+1]=x+1,a[n+2]=x-2;
    	    int now=1;
    	    for (int i=1;i<n-1;i++)
    		{
    		    if (now==x-2) now=x+2;
    		    a[i]=now++;
    		}
    	    for (int i=n+3;i<2*n;i++)
    		{
    		    if (now==x-2) now=x+2;
    		    a[i]=now++;
    		}
    	}
        puts("Yes");
        for (int i=1;i<2*n;i++) printf("%d ",a[i]);puts("");
        return 0;
    }
    
  • 相关阅读:
    Tips——RN HTML两端通信
    Tips——RN如何动态地添加删除组件
    Tips——RN webview如何实现首次加载自动登录及后续定时登录
    Between Us 1 生命的起源
    获取当前工作路径和当前模块路径
    从标准输出和读入
    字符串赋值操作
    char,string和CString转换
    字符串结束标志
    Lenovo GTX960M 配置CUDA
  • 原文地址:https://www.cnblogs.com/Alseo_Roplyer/p/10189171.html
Copyright © 2020-2023  润新知