Tile Code 拼木板

本文介绍了一个关于“绿色松坡”自行车交通系统项目,其中每个自行车将被赋予一个长度为n的瓷砖编码,由1×2、2×1和2×2的瓷砖在2×n矩形板上构成,不重叠且覆盖所有单元格。问题求解如何统计不同瓷砖编码的数量,分别针对奇数和偶数长度的编码给出了不同的计算方法。

3904 - Tile Code
Asia - Seoul - 2007/2008
PDF   Submit   Ranking

 

The city of Songpa is now carrying out a project to build a bicycle transportation system called 鈥榞reen Songpa.鈥?By the end of this year, citizens and visitors alike will be able to pick up and drop off bicycles throughout the city. Recently, it was decided to attach a number tag to each bicycle for management use. The bicycles will be under control of the city鈥檚 traffic system.

The number tag contains a tile code of length n , which consists of 1×2 , 2×1 , and 2×2 tiles placed on a 2×n rectangular plate in a way that every cell of the plate is covered by exactly one tile. The plate is divided into 2n cells of size 1×1 . Of course, no two tiles are allowed to overlap each other. The 2×5 plate and a tile code of length 5 are shown in Figures 1 and 2, respectively. The code will always be read from left to right. However, there is no distinction between the top side and the bottom side of the code. The code may be turned upside down. The code shown in Figure 3 is essentially the same code as in Figure 2.


 
Given a positive integer n , the project director Dr. Yang wants to know how many tile codes of length n there are, that is, the number of ways to place the three kinds of tiles into a 2×n rectangular plate subject to the above conditions. Write a program that can help him.


Input 
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case is given in a single line, which contains a positive integer n , 3n30 .


Output 
Your program is to write to standard output. Print exactly one line for each test case. The line should contain the number of tile codes of length n .


Sample Input 

2
3
4


Sample Output 

3
8

cnt[i]保存的是不忽略左右顺序的,但是左右不能重复;ans保存的是忽略左右顺序的,
当i是奇数的时候,中间是一条2*1的板,左右重复的情况一共是cnt[i/2],cnt[i]+cnt[i/2]表示不忽略左右顺序从左到右和从右到左两种情况之和,故ans[i]= (cnt[i]+cnt[i/2])/2;
当i是偶数的时候,有三种情况:中间是2*2,中间是两个1*2,和中间是一条缝,此时左右重复的分别是cnt[i/2-1],cnt[i/2-1],cnt[i/2],cnt[i]+cnt[i/2]+cnt[i/2-1]+cnt[i/2-1]表示不忽略左右顺序从左到右和从右到左两种情况之和,故ans[i]=(cnt[i]+cnt[i/2]+cnt[i/2-1]*2)/2;


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int cnt[40]={0,1,3};
    for(int i=3;i<=30;i++) cnt[i]=cnt[i-1]+2*cnt[i-2];
    int ans[40]={0,1,3};
    for(int i=3;i<=30;i++)
    {
        if(i&1)  ans[i]=(cnt[i]+cnt[i/2])/2;
        else ans[i]=(cnt[i]+cnt[i/2]+cnt[i/2-1]*2)/2;
    }  
    int ci;scanf("%d",&ci);
    while(ci--)
    {
        int n;
        scanf("%d",&n);
        printf("%d/n",ans[n]);
    }
    return 0;
}       

 

### OpenSlide Tile 接方法及实现 OpenSlide 是一个用于读取虚拟幻灯片图像文件的库,支持多种专有格式。为了进行 tile接操作,可以利用 Python 中的 `openslide-python` 库来获取各个 tile 并将其组合成完整的图像。 #### 获取并安装依赖项 确保已经按照官方文档说明完成了 OpenSlide 及其 Python 绑定的安装[^1]: 对于 Windows 用户来说,可以从指定网站下载预编译版本,并遵循给定指南完成设置过程。 #### 实现代码示例 下面是一个简单的例子展示如何通过遍历所有 tiles 来创建整张图片: ```python import numpy as np from PIL import Image import openslide def stitch_tiles(svs_file_path, output_image_path): slide = openslide.OpenSlide(svs_file_path) # 获取整个slide的信息 dimensions = slide.dimensions # 创建一个新的空白图像作为最终结果的基础 stitched_img = Image.new('RGB', (dimensions[0], dimensions[1])) level_dimensions = slide.level_dimensions[0] for y in range(0, level_dimensions[1]): for x in range(0, level_dimensions[0]): region_size = (256, 256) # 假设每个tile大小为256*256像素 try: img_tile = slide.read_region((x * 256, y * 256), 0, region_size).convert('RGB') box = (x * 256, y * 256, (x + 1) * 256, (y + 1) * 256) stitched_img.paste(img_tile, box=box) except Exception as e: print(f"Error reading tile at ({x},{y}): {e}") stitched_img.save(output_image_path) if __name__ == "__main__": svs_file_path = "path_to_your_svs_file.svs" output_image_path = "output_stitched_image.png" stitch_tiles(svs_file_path, output_image_path) ``` 这段脚本会逐个读取 SVS 文件中的每一个 tile ,并将它们粘贴到新的大图中相应位置上形成完整的大图[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值