This commit is contained in:
Zengtudor 2025-08-08 17:40:22 +08:00
parent 85982b9834
commit 191d5c1b12
3 changed files with 165 additions and 0 deletions

8
.clang-format Normal file
View File

@ -0,0 +1,8 @@
BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignConsecutiveMacros: true
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: None # 明确禁止简短函数内联为单行
AllowShortIfStatementsOnASingleLine: false
BreakBeforeBraces: Attach # 大括号不换行
IndentCaseLabels: true # 设置 case 标签缩进

69
src/8/8/808calculate.cpp Normal file
View File

@ -0,0 +1,69 @@
#include <iostream>
#include <vector>
#include <numeric> // std::accumulate
// 使用 long long 来防止数字和或进位总数溢出
using ll = long long;
int main() {
// ----------------- 输入输出优化 -----------------
// 在 OI/ACM 竞赛中,这可以显著加快大规模数据的读写速度
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
// ----------------- 读取输入 -----------------
int n;
std::cin >> n;
std::vector<ll> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
// ----------------- 核心算法 -----------------
ll total_carries = 0; // 用于累计所有位的总进位次数
ll carry_from_last_digit = 0; // 从上一位传递到当前位的进位总数
// 循环处理每一位从个位10^0开始直到所有数字都处理完毕
// 循环终止条件当所有数字都变为0并且没有从低位传来的进位时计算结束
bool all_zeros = false;
while (!all_zeros || carry_from_last_digit > 0) {
ll current_digit_sum = 0; // 当前位所有数字的总和
all_zeros = true; // 假设本轮循环后所有数字都将变为0
// 遍历序列中的每一个数
for (int i = 0; i < n; ++i) {
// 如果数字大于0说明它还有未处理的位
if (a[i] > 0) {
// a[i] % 10 取出当前数字的最低位(即当前处理的位)
current_digit_sum += a[i] % 10;
// 将该数字除以10为其在下一轮更高位的计算做准备
a[i] /= 10;
// 如果 a[i] 在处理后仍然大于0说明它还有更高位
// 因此循环需要继续
if (a[i] > 0) {
all_zeros = false;
}
}
}
// 将当前位所有数字的和与来自上一位的进位相加
ll total_sum_at_this_digit = current_digit_sum + carry_from_last_digit;
// 计算将要传递到下一位(更高位)的进位总数
// 例如如果当前位总和为123则有12个进位到下一位
ll new_carries = total_sum_at_this_digit / 10;
// 将本位产生的进位累加到总进位次数中
total_carries += new_carries;
// 更新 carry_from_last_digit为下一轮更高位的计算做准备
carry_from_last_digit = new_carries;
}
// ----------------- 输出结果 -----------------
std::cout << total_carries << std::endl;
return 0;
}

88
src/8/8/808string.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
bool isgoodsimple(const string &s) {
int len = s.length();
if (len == 0)
return false;
for (int p = 1; p <= len / 2; ++p) {
if (len % p == 0) {
string t = s.substr(0, p);
bool isp = true;
for (int k = p; k < len; k += p) {
if (s.substr(k, p) != t) {
isp = false;
break;
}
}
if (isp) {
return false;
}
}
}
return true;
}
void solve() {
string s;
cin >> s;
int n = s.length();
vector<int> dp(n + 1, INF);
vector<long long> cnt(n + 1, 0);
dp[0] = 0;
cnt[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < i; ++j) {
string sub = s.substr(j, i - j);
if (isgoodsimple(sub)) {
if (dp[j] == INF)
continue;
if (dp[j] + 1 < dp[i]) {
dp[i] = dp[j] + 1;
cnt[i] = cnt[j];
} else if (dp[j] + 1 == dp[i]) {
cnt[i] = (cnt[i] + cnt[j]) % MOD;
}
}
}
}
cout << dp[n] << endl;
cout << cnt[n] << endl;
}
int main() {
iostream::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}