如何将矢量分割成n"几乎等于"部分 [英] How to split a vector into n "almost equal" parts

查看:128
本文介绍了如何将矢量分割成n"几乎等于"部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想合并大量使用ImageMagick的CONVERT.EXE图像的问题,但在Windows下我有一个8192字节长的命令行限制。

I have a problem that I would like to merge a large number of images using ImageMagick's convert.exe, but under Windows I have a 8192 byte long command line limit.

我此解决方案是将任务分割成更小的子任务,运行它们,并执行它结合在一起的最终任务。

My solution to this is to split the task into smaller sub-task, run them, and do a final task which combines them together.

我的想法是写一个函数,该函数的图像和整数的向量,并拆分成矢量均具有几乎等于部分n个子向量。

My idea is to write a function, which takes a vector of images and an integer, and splits the vector into n sub-vector all having "almost equal" parts.

因此​​,举例来说,如果我想11分成3组,这将是4-4-3。

So for example if I would like to split 11 into 3 groups it would be 4-4-3.

你能告诉我,我怎么能做到这一点在C ++?我的意思是,编写一个函数

Can you tell me how can I do it in C++? I mean, to write a function

split_vec( const vector<image> &images, int split )

这不分裂?

另外,你能告诉我什么是做的最有效的方式如果我不需要创建新载体,只需通过分部分重复?像的std :: SUBSTR 的std ::字符串函数

Also, can you tell me what is the most efficient way to do if I don't need to create new vectors, just iterate through the sub-parts? Like the std::substr function with std::string?

注:我已经使用了升压的项目,所以如果在加速这一一些很好的工具,那么它适合我

推荐答案

要得到各部分的尺寸基数,只需通过零件数除以总数:11/3 = 3,显然,有些零件将需要更大的比得到适当的总量,但这只是剩下的11%3 = 2,所以,现在你知道份2的大小为3 + 1,和任何的遗留将会3.

To get a base number for the size of each part, simply divide the total by the number of parts: 11/3 = 3. Obviously some of the parts will need to be bigger than that to get the proper total, but that's just the remainder: 11 % 3 = 2. So now you know that 2 of the parts will be size 3+1, and whatever's left over will be 3.

这篇关于如何将矢量分割成n&QUOT;几乎等于&QUOT;部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆