【Kattis - triangle 】Sierpiński Circumference(数学,求位数,取对数或Java)

题干:

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

 解题报告:

   推出公式发现需要求3* (1.5)^n的位数,处理方法很多,可以double存答案,然后每一次进到1e9的时候,就答案+=9,数字/=1e9,最后肯定得到了一个1e9范围以内的数字,再单独处理就行。也可以用Java的大整数类先算出分母和分子,再做除法(向下取整),然后按位处理。

   也可以直接用C++中取log的操作得到答案。整数n的位数就是log10(n) + 1.

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const double eps=1e-8;
int main()
{int t,q,i,j,n,cnt=0,ans;while(scanf("%d",&n)!=EOF){ans=log10(3)+n*log10(3.0/2);ans++;printf("Case %d: %d\n",++cnt,ans);}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440615.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

米莱狄的机器人是_王者荣耀2.22更新:米莱狄机器人化身超级兵,狂铁将成T1级战士...

王者荣耀体验服在刚刚迎来了一次小更新&#xff0c;主要针对两位海都英雄的调整&#xff0c;这也是米莱狄和狂铁自上回加强后获得的第二波BUFF&#xff0c;一起来看看这次调整能否让这两位冷门英雄成为上分首选吧&#xff01;狂铁在上回的调整中移除了大招护盾伤害和汲取能量的…

如何云服务器销售,如何云服务器销售

如何云服务器销售 内容精选换一换云耀云服务器(Halo Elastic Cloud Server&#xff0c;HECS)是可以快速搭建简单应用的新一代云服务器&#xff0c;具备独立、完整的操作系统和网络功能。提供快速地应用部署和简易的管理能力&#xff0c;适用于网站搭建、开发环境等低负载应用场…

中原标准时间对时_GPS对时系统(时间同步系统)应用电子政务

GPS对时系统&#xff08;时间同步系统&#xff09;应用电子政务GPS对时系统&#xff08;时间同步系统&#xff09;应用电子政务摘要&#xff1a;随着电子政务的不断发展&#xff0c;许多省份都建立了自己的政务网络&#xff0c;使用的网络设备和服务器日益增多&#xff0c;这些…

【牛客 - 272C】Balls(概率dp,结论,思维)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/272/C 来源&#xff1a;牛客网 有一个盒子&#xff0c;里面有一个黑球和一个白球。每次随机取出盒子中的一个球&#xff0c;并将两个与取出球同色的球放进盒子&#xff08;就是随机一种颜色将其个数…

邮件发送类_10 分钟实现 Spring Boot 发生邮件功能

基础知识什么是SMTP&#xff1f;什么是IMAP&#xff1f;什么是POP3&#xff1f;IMAP和POP3协议有什么不同呢&#xff1f;进阶知识什么是JavaMailSender和JavaMailSenderImpl&#xff1f;如何通过JavaMailSenderImpl发送邮件&#xff1f;为什么JavaMailSenderImpl 能够开箱即用 …

mess系统可以读取opc服务器,C3. Messages

数据字段!Time Data Data Data Data Data Data Data Data!Time Data Data Data Data Data Data Data Data!Time Data Data Data Data Data Data Data Data!Time Data Data Data Data Data Data Data Data……………………….以下是数据文件的示例。Fig. C 2.11 Sample Configur…

【牛客 - 272D】Where are you(Tarjan求桥)

题干&#xff1a; 小p和他的朋友约定好去游乐场游玩&#xff0c;但是他们到了游乐场后却互相找不到对方了。 游乐场可以看做是一张n个点&#xff0c;m条道路的图&#xff0c;每条道路有边权wi&#xff0c;表示第一次经过该道路时的花费&#xff08;第二次及以后经过时花费为…

sharding分表后主键_Sharding-JDBC 使用入门和基本配置

一、什么是Sharding-JDBCSharding-JDBC定位为轻量级Java框架&#xff0c;在Java的JDBC层提供的额外服务。它使用客户端直连数据库&#xff0c;以jar包形式提供服务&#xff0c;无需额外部署和依赖&#xff0c;可理解为增强版的JDBC驱动&#xff0c;完全兼容JDBC和各种ORM框架。…

操作表格_Excel表格基础操作-新手入门级

今日新学了几个基础操作&#xff0c;觉得很有意思&#xff0c;分享给大家。不过真心觉得&#xff0c;有些操作当时学会了&#xff0c;长时间不用&#xff0c;转眼就忘了&#xff1b;另一方面&#xff0c;如果购买相关课程&#xff0c;学着也没什么意思&#xff0c;我前段时间买…

dmsetup remove_all 这命令干啥的_分一个小知识,服务器上的一个解压与压缩文件的命令....

在服务器上对文件做解压操作,是一件非常常见的操作,如安装软件就有很多是要用的到这个操作的.去官网下载一个压缩包,然后解压,编译,再安装.当然网上是能找到相应的命令操作.但是每次都要去找命令,就算记住了,不知道为什么要这样去使用,那么如果不经常使用那还是会忘记的.所以要…

倍福 在 vs 里 编程 是怎么做到的_截图里的文字要改,字体怎么做到一模一样?...

大家是不是碰到过这么一个尴尬的情况&#xff1a;一个截图里有一个错别字&#xff0c;或者其中一小段文字要修改&#xff0c;可是苦于找不到源文件&#xff0c;又没办法找出和原来文字一模一样的字体。每次遇到这样的情况你都是怎么处理的呢&#xff1f;火箭君今天给大家介绍一…

*【POJ - 3659】Cell Phone Network (树形dp,最小支配集)

题干&#xff1a; Farmer John has decided to give each of his cows a cell phone in hopes to encourage their social interaction. This, however, requires him to set up cell phone towers on his N (1 ≤ N ≤ 10,000) pastures (conveniently numbered 1..N) so the…

【POJ - 2632】Crashing Robots(模拟)

题干&#xff1a; In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and all robots occup…

pandownload用户未登录_Pandownload再度复活,下载速度飙升到10MB/s以上

PanDownload再度复活版&#xff0c;此版镜像服务器由新城旧梦维护卢本伟修改版&#xff0c;基本都是维持在10M/S的下载速度&#xff0c;如果你的宽带够大&#xff0c;下载速度会更快&#xff0c;无需安装即可免费使用&#xff0c;但是需要登陆才能下载。(Pandownload卢本伟修改…

momentjs转换格式_Moment.js+Vue过滤器的使用,各种时间格式转换为YYYY-MM-DD HH:mm:ss格式...

前言这篇文章将Moment.js与vue过滤器连用。如果不会过滤器的朋友&#xff0c;可以先看这篇文章vue过滤器一、Moment.js是什么&#xff1f;Moment.js是JavaScript 日期处理类库。使用场景&#xff1a;vue项目中经常需要将时间戳转换为各种时间格式再显示。二、使用步骤1.安装这里…

【HDU - 1943】Ball bearings(几何问题)

题干&#xff1a; The Swedish company SKF makes ball bearings. As explained by Britannica Online, a ball bearing is “one of the two types of rolling, or anti friction, bearings (the other is the roller bearing). Its function is to connect two machine mem…

mysql显示修改密码_MySQL修改密码

第一种方式&#xff1a;最简单的方法就是借助第三方工具Navicat for MySQL来修改&#xff0c;方法如下&#xff1a;1、登录mysql到指定库&#xff0c;如&#xff1a;登录到test库。2、然后点击上方“用户”按钮。3、选择要更改的用户名&#xff0c;然后点击上方的“编辑用户”按…

mysql 磁盘组_有效管理 ASM 磁盘组空间

ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 错误会ORA-15041: diskgroup space exhausted 对您的数据库环境的直接和间接影响&#xff1f;与 ASM 磁盘组相关的磁盘空间问题和 ORA-15041 …

【HDU - 1561】The more, The Better(树形背包,dp,依赖背包问题与空间优化,tricks)

题干&#xff1a; ACboy很喜欢玩一种战略游戏&#xff0c;在一个地图上&#xff0c;有N座城堡&#xff0c;每座城堡都有一定的宝物&#xff0c;在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物。但由于地理位置原因&#xff0c;有些城堡不能直接攻克&#xff0c;要攻克这些…

【CodeForces - 616C 】The Labyrinth点石成金(并查集,dfs)

题干&#xff1a; 小O无意间发现了一张藏宝图&#xff0c;它跟随藏宝图的指引来到了一个宫殿&#xff0c;宫殿的地板被分成了n*m块格子&#xff0c;每个格子上放置了金子或者石头 藏宝图告诉小O&#xff0c;它可以选择一块石头变成金子&#xff0c;并且带走与变化后的金子联通…