博客
关于我
19年 湘潭邀请赛
阅读量:303 次
发布时间:2019-03-03

本文共 1409 字,大约阅读时间需要 4 分钟。

代码优化后的内容

模拟n叉树结构的代码优化

#include 
#include
#include
#include
#include
using namespace std;int main() { int k, m, n, N; long long p; while (scanf("%d%d%d%lld", &k, &m, &n, &p)) { vector
a(k + 1, 0); for (int i = 1; i <= k; ++i) { scanf("%lld", &a[i]); } sort(a.begin() + 1, a.end()); if (n == 1) { N = m; } else { N = (pow(n, m) - 1) / (n - 1); } long long ans = 0; for (int i = 1; i < N; ++i) { int parent = i / n; if (parent == 0) { parent = i; } a[i] = (a[parent] % p + a[i] % p) % p; ans = (ans + a[i]) % p; } cout << ans << endl; } return 0;}

字符串处理问题的代码优化

#include 
#include
#include
#include
#include
using namespace std;int main() { int n, a[10]; string s; while (cin >> n >> s) { memset(a, 0, sizeof(a)); for (size_t i = 0; i < n; ++i) { if (s[i] == 'x') { a[1]++; } else if (s[i] == 't' && a[1]) { a[2]++; a[1]--; } else if (s[i] == 'C' && a[2]) { a[3]++; a[2]--; } else if (s[i] == 'p' && a[3]) { a[4]++; a[3]--; } else if (s[i] == 'c' && a[4]) { a[5]++; a[4]--; } } cout << a[5] << endl; } return 0;}

转载地址:http://hwfm.baihongyu.com/

你可能感兴趣的文章
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node.js 函数是什么样的?
查看>>
Node.js 历史
查看>>
Node.js 在个推的微服务实践:基于容器的一站式命令行工具链
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>