diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..03b88f4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,8 @@ +BasedOnStyle: Microsoft +AccessModifierOffset: -4 +AlignConsecutiveMacros: true +AlignTrailingComments: true +AllowShortFunctionsOnASingleLine: None # 明确禁止简短函数内联为单行 +AllowShortIfStatementsOnASingleLine: false +BreakBeforeBraces: Attach # 大括号不换行 +IndentCaseLabels: true # 设置 case 标签缩进 \ No newline at end of file diff --git a/src/8/8/808calculate.cpp b/src/8/8/808calculate.cpp new file mode 100644 index 0000000..26053ab --- /dev/null +++ b/src/8/8/808calculate.cpp @@ -0,0 +1,69 @@ +#include +#include +#include // 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 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; +} diff --git a/src/8/8/808string.cpp b/src/8/8/808string.cpp new file mode 100644 index 0000000..16238ab --- /dev/null +++ b/src/8/8/808string.cpp @@ -0,0 +1,88 @@ +#include +#include +#include + +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 dp(n + 1, INF); + + vector 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; +}