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

你可能感兴趣的文章
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
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.
查看>>