专栏文章

题解:SP94 MAYA - Numeral System of the Maya

SP94题解参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miokyp7t
此快照首次捕获于
2025/12/02 20:54
3 个月前
此快照最后确认于
2025/12/02 20:54
3 个月前
查看原文

题目大意

将一个特殊进制的数转换为十进制。

思路

对于当前这一位,. 表示 1、- 表示 5。我们可以遍历当前这一位并统计答案。
对于每一位的基数,不难发现:除了第 3 位,其余的都是前一位的 20 倍,因此可以得出以下结论。
wx={1x=120x=218×20x2x<2w_x = \begin{cases} 1 & x = 1 \\ 20 & x = 2 \\ 18 \times 20^{x-2} & x < 2 \end{cases}
因此,答案就是每一位的值乘上当前这一位的基数再求和。

代码

CPP
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n;
string s;

int num(string x) {
	if (x == "S") return 0;
	int cnt1 = 0, cnt2 = 0;
	for (char c : x) {
		if (c == '.') cnt1++;
		if (c == '-') cnt2++;
	}
	return cnt1 + cnt2 * 5;
}

int w(int x) {
	if (x == 1) return 1;
	if (x == 2) return 20;
	return 18 * pow(20, x - 2);
}

signed main() {
	while (cin >> n, n) {
		getline(cin, s);
		int ans = 0;
		for (int i = n; i; i--) {
			getline(cin, s);
			ans += num(s) * w(i);
		}
		cout << ans << endl;
	}
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...