我有Ñ的不同长度的字符串小号1,S 2,...,S Ñ我要显示在终端上Ç列.终端的宽度为m个字符.每列i具有一定宽度w i,其等于该列中最长条目的宽度.每对列之间有空间的一定量的小号.包括空间之间的所有列的总宽度不能大于端子的宽度(w 1 + w 2 + ... + w c +(c-1)·s≤m).每列应包含⌈n / c⌉字符串,除非n不能由c均匀分割,在这种情况下,最后几列应缩短一个条目,或者只有最后一列应短,取决于字符串是否排列横向或向下.
是否存在有效的(例如O(n·w),其中w = max(w 1,w 2,...,w n))算法,以计算出我可以适应c列的最大列数,如果......
字符串排列整齐
string1 string2 string3 string4
string5 string6 string7 string8
string9 string10
Run Code Online (Sandbox Code Playgroud)弦向下排列
string1 string4 string7 string10
string2 string5 string8
string3 …Run Code Online (Sandbox Code Playgroud)考虑一下 C++ 中的这个函数:
void foo(uint32_t *a1, uint32_t *a2, uint32_t *b1, uint32_t *b2, uint32_t *o) {
while (b1 != b2) {
// assert(0 <= *b1 && *b1 < a2 - a1)
*o++ = a1[*b1++];
}
}
Run Code Online (Sandbox Code Playgroud)
其目的应该足够明确。不幸的是,b1包含随机数据并垃圾缓存,成为foo我的程序的瓶颈。无论如何我可以优化它吗?
这是一个 SSCCE,应该类似于我的实际代码:
#include <iostream>
#include <chrono>
#include <algorithm>
#include <numeric>
namespace {
void foo(uint32_t *a1, uint32_t *a2, uint32_t *b1, uint32_t *b2, uint32_t *o) {
while (b1 != b2) {
// assert(0 <= *b1 && *b1 < a2 - …Run Code Online (Sandbox Code Playgroud)