【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;狂铁在上回的调整中移除了大招护盾伤害和汲取能量的…

ajax post参数长度限制,Ajax中的POST数据大小是否有限制?

我想使用jQuery Ajax将我的页面中的数据数组发送到MVC Action。这里是我的jQuery代码&#xff1a;Ajax中的POST数据大小是否有限制&#xff1f;$(#btnSave).click(function() {result [];$(#tblMatters tbody tr.mattersRow).each(function() {if (!($(this).hasClass(warning…

【HDU - 5943】Kingdom of Obsession(数论,素数间隔结论,构造,思维,匈牙利算法,匹配问题)

题干&#xff1a; There is a kindom of obsession, so people in this kingdom do things very strictly. They name themselves in integer, and there are nn people with their id continuous (s1,s2,⋯,sn)(s1,s2,⋯,sn) standing in a line in arbitrary order, be mor…

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

如何云服务器销售 内容精选换一换云耀云服务器(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;就是随机一种颜色将其个数…

打印机显示发送任务到服务器失败,G-FAX单机版操作指引-AOFAX—传真服务器.DOC

G-FAX单机版操作指引-AOFAX—传真服务器3G-FAX局域网版操作指南基本配备&#xff1a;3G-FAX数码传真主机一台、一张3G-FAX管理器软件光盘&#xff0c;串口线一条、电话线一条&#xff0c;带有传真、打印、扫描快捷键的智能扫描仪一台(选配)。硬件连接&#xff1a;1、用串口线连…

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

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

【POJ - 2186】Popular Cows (Tarjan缩点)

题干&#xff1a; Every cows dream is to become the most popular cow in the herd. In a herd of N (1 < N < 10,000) cows, you are given up to M (1 < M < 50,000) ordered pairs of the form (A, B) that tell you that cow A thinks that cow B is popula…

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框架。…

【蓝桥杯官网试题 - 基础练习】 矩形面积交 (几何)

题干&#xff1a; 问题描述 平面上有两个矩形&#xff0c;它们的边平行于直角坐标系的X轴或Y轴。对于每个矩形&#xff0c;我们给出它的一对相对顶点的坐标&#xff0c;请你编程算出两个矩形的交的面积。 输入格式 输入仅包含两行&#xff0c;每行描述一个矩形。   在每行中…

实现运动轨迹_【自动驾驶】运动规划丨速度规划丨时间维度

运动规划是自动驾驶技术栈中的关键一步&#xff0c;负责把上游的孤立、异构、模糊的多方面信息整合成自洽的运动轨迹&#xff08;trajectory&#xff09;&#xff1b;好的轨迹需要满足多方面的要求&#xff0c;其中最重要的方面包括安全性&#xff08;safety&#xff09;和舒适…

【HDU - 1247】Hat’s Words(字典树,预处理,tricks)

题干&#xff1a; A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary. You are to find all the hat’s words in a dictionary. Input Standard input consists of a number of lowercase words, one …

mysql操作json优点和缺点_MySQL与JSON-为什么?

我正在设计一个小的网络应用程序/游戏。 哪个更好&#xff1a;MySQL表或json文件&#xff1f; 它们都存储信息。 它们都可以由PHP解析。 优点/缺点是什么&#xff1f;这就是我的意思&#xff1a;username | password-------------------seefour | abc123与{"username"…

【csust】最小素因子问题(树状数组)

题干&#xff1a; http://csustacm.com:4803/problem/1083 Description 寒冰射手艾希新学会了一个技能&#xff0c;艾希通过这个技能成为了一名声名远扬的神箭手&#xff0c;从此再也无人敢侵犯弗雷尔卓德&#xff01; 这个技能的描述如下&#xff08;假设英雄联盟内的每个…

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

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

【csust】寻宝(贪心,思维)

题干&#xff1a; Description 在一维坐标轴上有许多宝藏&#xff0c;总共n种宝藏&#xff0c;每种宝藏有k个。现在共k个人寻宝&#xff0c;k个人初始位置可以位于任意点。但是每人需要按指定顺序捡起宝藏&#xff08;1->2->3->...->n&#xff0c;先捡第1种&…

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

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