Sierpiński Circumference Kattis - triangle

本文深入探讨了数学家Sierpiński于1915年提出的Sierpiński三角形的迭代构造过程,通过算法描述了如何从初始三角形开始,经过无限次迭代形成无限点集的过程。特别地,文章关注了有限迭代次数下,所有黑色三角形周长总和的计算,提出了一种计算其整数部分所需十进制位数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Polish mathematician Wacław Sierpiński (1882-1969) described the 2D geometric figure known as the Sierpiński triangle as part of his work on set theory in 1915. The triangle, which is really an infinite collection of points, can be constructed by the following algorithm:

  1. The initial shape is a solid triangle.

  2. Shrink the current shape to half its dimensions (both height and width), and make two more copies of it (giving three copies total).

  3. Arrange the three copies so that each touches the two others at their corners. Set the current shape to be the union of these three.

  4. Repeat from step 2.

Here is an illustration of the first few iterations:

 

\includegraphics[width=0.5\textwidth ]{sierpinski_depth_0}

\includegraphics[width=0.5\textwidth ]{sierpinski_depth_1}

\includegraphics[width=0.5\textwidth ]{sierpinski_depth_2}

\includegraphics[width=0.5\textwidth ]{sierpinski_depth_3}

\includegraphics[width=0.5\textwidth ]{sierpinski_depth_4}

iteration

00

11

22

33

44

As the iterations go to infinity, this process creates an infinite number of connected points. However, consider the case of a finite number of iterations. If the initial triangle has a circumference of 33, what is the sum of the circumferences of all (black) triangles at a given iteration? Write a program to find out not the exact circumference, but the number of decimal digits required to represent its integer portion. That is, find the number of decimal digits required to represent the largest integer that is at most as large as the circumference.

Input

Each test case is a line containing a non-negative integer 0≤n≤100000≤n≤10000 indicating the number of iterations.

Output

For each case, display the case number followed by the number of decimal digits required to represent the integer portion of the circumference for the given number of iterations. Follow the format of the sample output.

Sample Input 1Sample Output 1
0
1
5
10
100
Case 1: 1
Case 2: 1
Case 3: 2
Case 4: 3
Case 5: 19

 

题意:每一次一个三角形会以三角形边长的一半分成小的三角形,问第i次分裂后所有黑色三角形周长的和是多少位

我们很容易推出 周长=3*1.5^n,那么位数等于log10(3*pow(1.5,n))=log10(3)+n*log10(1.5)向上取整。

#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int cas=1,n;
	while(~scanf("%d",&n))
	{
		printf("Case %d: %.0lf\n",cas++,ceil(log10(3)+n*log10(1.5)));
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值