1 条题解

  • 0
    @ 2026-9-23 23:21:32

    思路分析

    观察数据范围,感觉像是什么 log⁡n+O(1)\log n+O(1) 一类的范围。于是考虑按照进制拆分一下。

    首先考虑一类最基本的元素 2×n2\times n,这样的一个空白区域从左上角走到右下角的方案数恰为 nn。

    于是我们考虑能不能采用二进制解决。显然最紧凑的安排方式是这样的:

    $$\begin{matrix} . & . & * & * & * & \dots \\ . & . & . & * & * & \dots \\ * & . & . & . & * & \dots \\ * & * & . & . & . & \dots \\ * & * & * & . & . & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \end{matrix}$$

    但是这样做似乎无法扩展:容易注意到如果答案不是 2d2^d 我们就完蛋了,我们没有办法整出来几个独立的 22 的次幂(虽然实际上有办法做到)。

    此时鬼脑发力了。我认为类似二次幂这样拆肯定不行,根本原因在于我没有办法单独引出来几个分叉来消除掉余数。

    于是我考虑 33 进制,发现空位不足以产生出余 22 时的贡献(实际上也是可以的)。我又考虑 44 进制,发现 44 进制竟然是可以的。

    仍然考虑紧凑布局:

    $$\begin{matrix} . & . & . & . & * & \dots \\ . & . & . & . & . & \dots \\ * & * & * & . & . & \dots \\ * & * & * & . & . & \dots \\ * & * & * & . & . & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \end{matrix}$$

    考虑第一个 2×42\times 4 目标是产生 44 倍后续贡献。如果此时  mod 4\bmod 4 有余数,那么我们应该及时把多余部分处理掉。

    发现处理是简单的:

    如果  mod 4=1\bmod 4=1,那么我们需要导出一个贡献为 11 的支路。一种方法如下所示:

    $$\begin{matrix} . & . & . & . & * & \dots \\ . & . & . & . & . & \dots \\ . & * & * & . & . & \dots \\ . & * & * & . & . & \dots \\ . & * & * & . & . & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \end{matrix}$$

    如果  mod 4=2\bmod 4=2,那么我们需要导出一个贡献为 11 的支路。一种方法如下所示:

    $$\begin{matrix} . & . & . & . & * & \dots \\ . & . & . & . & . & \dots \\ * & . & * & . & . & \dots \\ * & . & * & . & . & \dots \\ * & . & * & . & . & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \end{matrix}$$

    如果  mod 4=3\bmod 4=3,那么我们需要导出一个贡献为 11 的支路。一种方法如下所示:

    $$\begin{matrix} . & . & . & . & * & \dots \\ . & . & . & . & . & \dots \\ . & . & * & . & . & \dots \\ * & . & * & . & . & \dots \\ * & . & * & . & . & \dots \\ \dots & \dots & \dots & \dots & \dots & \dots \\ \end{matrix}$$

    于是此题可解,可以把矩形大小开到 6464,参考代码如下:

    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    int n,m; char a[65][65];
    signed main(){
    	ios::sync_with_stdio(0);
    	memset(a,'#',sizeof a); cin>>n; m=64;
    	for(int i=1;i<=64;++i) a[64][i]=a[i][64]='.';
    	for(int px=1,py=1;px<=60;px+=4,py+=4){
    		a[px+0][py+0]=a[px+0][py+1]=a[px+0][py+2]=a[px+0][py+3]='.';
    		a[px+1][py+0]=a[px+1][py+1]=a[px+1][py+2]=a[px+1][py+3]='.';
    		a[px+1][py+3]=a[px+2][py+3]=a[px+3][py+3]=a[px+4][py+3]='.';
    		a[px+1][py+4]=a[px+2][py+4]=a[px+3][py+4]=a[px+4][py+4]='.';
    		if((n&3)==1)
    			for(int i=px+2;i<=64;++i)
    				a[i][py+0]='.';
    		else if((n&3)==2)
    			for(int i=px+2;i<=64;++i)
    				a[i][py+1]='.';
    		else if((n&3)==3){
    			a[px+2][py+0]='.';
    			for(int i=px+2;i<=64;++i)
    				a[i][py+1]='.';
    		}
    		n>>=2;
    		if((n&3)==1)
    			for(int i=py+5;i<=64;++i)
    				a[px+1][i]='.';
    		else if((n&3)==2)
    			for(int i=py+5;i<=64;++i)
    				a[px+2][i]='.';
    		else if((n&3)==3){
    			a[px+1][py+5]='.';
    			for(int i=py+5;i<=64;++i)
    				a[px+2][i]='.';
    		}
    		n>>=2;
    	}
    	cout<<m<<endl;
    	for(int i=1;i<=m;++i,cout<<endl)
    		for(int j=1;j<=m;++j)
    			cout<<a[i][j];
    }
    
    • 1

    [POI 2020/2021 R2] 棋盘 / Projekt planszy

    信息

    ID
    7534
    时间
    1000ms
    内存
    64MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者