Kattis - triangle 【数学】
2024-08-29 06:51:50
题意
求第N个迭代三角形 中 所有黑色三角形的周长的整数部分的位数
思路
该三角形的周长是
3^(n + 1)/ 2 ^ (n)
然后 可以用 long double 存下来
再求位数 就可以
AC 代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;
ld arr[maxn];
int ans[maxn];
int f(ld x)
{
int ans = 0;
while (x >= 1)
{
x /= 10;
ans++;
}
return ans;
}
int main()
{
arr[0] = 3;
ans[0] = 1;
for (int i = 1; i <= 10000; i++)
{
arr[i] = arr[i - 1] * (3.0 / 2);
ans[i] = f(arr[i]);
}
int n;
int count = 1;
while (~scanf("%d", &n))
printf("Case %d: %d\n", count++, ans[n]);
}
最新文章
- 【代码笔记】iOS-中国地图
- spring入门教程——笔记
- 如何创建 CSS
- JavaScript常用事件
- hdu 4715 Difference Between Primes
- Jalopy 之 HelloWorld —— Jalopy 在 MyEclipse 下的安装与使用
- debian清除无用的库文件(清理系统,洁癖专用)
- LNK1123: 转换到 COFF 期间失败: 文件无效或损坏[汇总]
- Ubuntu 创建快捷方式的方法
- 数据结构(LCT动态树):BZOJ 1036: [ZJOI2008]树的统计Count
- linux搭建邮件服务器
- [Unity 3D] Unity 3D 里的碰撞检测
- 像屎一样的 Spring Boot入门,总算有反应了
- php 查询mysql数据批量转为PDF文件二(批量使用wkhtmltopdf html导出PDF)
- parallel方法 异步并行执行
- Java中this和super关键字
- leecode第四题(寻找两个有序数组的中位数)
- AN2820 Driving bipolar stepper motors using a medium-density STM32F103xx microcontroller
- 自己写的一个jQuery分页插件
- python 乘法表、打印菱形