博客
关于我
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/

你可能感兴趣的文章
post为什么会发送两次请求?
查看>>
Post表单提交TextArea的值出现转译乱码问题 - Spring MVC处理表单提交
查看>>
Power BI 中的 Python 可视化需要什么设置?任何特定的 matplotlib 包版本或系统设置?
查看>>
Power BI:如何在 Power Query 编辑器中将 Python 与多个表一起使用?
查看>>
power english (3) main text -emotion mastery - focus
查看>>
POWER ENGLISH (6) - MODEL
查看>>
power english (1) —— passion
查看>>
Power English (1) 原文
查看>>
power English (3)原文
查看>>
POWER ENGLISH(7)- repetition
查看>>
SpringBoot中集成SpringBatch详细解析与实战示例(CSV文件读取十万条数据进行业务处理后写入Mysql数据库)
查看>>
powerbi 一张表在另外一张表中出现的数量_PowerBi之初步学习笔记
查看>>
QGIS怎样设置简体中文以及新建可编辑的多边形的图层
查看>>
PowerBuilder 使用自定义事件触发键盘Enter事件
查看>>
PowerCreatorCMS UploadResourcePic 任意文件上传漏洞复现
查看>>
PowerDesigner 使用的一些技巧(转)
查看>>
QGIS在Windows上下载安装与建立空间数据库连接
查看>>
PowerDesigner165安装婆姐汉花教程
查看>>
PowerDesigner使用教程:设置注释、默认值属性
查看>>
PowerDesigner使用教程:不显示背景网格
查看>>