Kattis - triangle 【数学】

mac2022-06-30  32

题意 求第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]); }

转载于:https://www.cnblogs.com/Dup4/p/9433244.html

相关资源:编写函数,判断输入的三个数字是否能构成三角形的三条边。def04.py
最新回复(0)