- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
问题听起来像这样,我们得到了 n 个文本,它们将被放置在 p 个磁带/乐队上(真的不知道英语中的等价物是什么,但我想你明白我在说什么谈论)。
为了阅读位于其中一个波段上位置 k 的文本,我们必须从特定波段上的位置 1,2,...,k 读取文本。每个文本都有自己的长度。
现在,我们必须找出一种将文本放置在 p 波段上的方法,以便我们获得最小的全局访问时间。全局访问时间是通过将每个波段的所有总访问时间相加得到的。
一个波段的总访问时间计算公式为:
n_
\ [L(T1)+L(T2)+...+L(Ti)]
/_
i=1
Now, that little drawing I did is SUM from 1 to n;
L(T i) is the length of T i;
T i is the text situated at position i on the respective band;
以下是“伪代码”中的等价物,以防有帮助:
n-number of texts;
Band[n]-array of texts
sum=0, sum2=0;
for(int i=0;i<n;i++)
{sum=0;
for(int j=0;j<=i;j++ )
sum=sum+Band[j].length;
sum2=sum2+sum; }
return sum2;
这里有一个例子来阐明这个问题:
say p is 3, so we get 3 bands
say n is 9, so we get 9 texts and the lengths are : 2, 3, 4, 5, 6, 7, 8, 9, 10
and they are placed on the bands in the following way:
band-1: 2, 5, 8 -> total accesing time of band-1: 24
band-2: 3, 6, 9 -> total accesing time of band-2: 30
band-3: 4, 7, 10 -> total accesing time of band-3: 36
the global accesing time: 24 + 30 + 36 = 90
最佳答案
我将文本位置称为磁带中特定文本之后出现的文本数量,它也表示文本将被读取多少次。
由于您只对访问时间的总和感兴趣,因此文本如何分组到磁带中没有实际意义,但每个文本的位置是什么,例如在相同位置但在不同磁带上切换 2 个文本不会' t 更改全局访问时间。虽然在不同位置切换 2 个不同大小的文本会改变时间,但通常较长的文本应放在较低的位置(靠近末尾)
该算法可以是贪婪的,从最长到最短的顺序遍历文本,并将每个文本放在文本最少的磁带之一的最后一个可用位置,例如,如果有 10 个文本和 5 个文本然后较长的 5 个文本将在每个磁带的末尾,而较短的 5 个文本将在其开头。
关于算法 - 如何将 n 个文本放置在 p 波段上,以使全局访问时间最短。每个文本都有自己的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40470588/
语句 1: [2,4,6,7,8].each do |i| (i % 2 == 0) || (puts "Not even" && break) puts i end 声明 2: [2
我有一张正在显示的卡片,上面有一些信息。我想将其包装在SingleChildScrollView中,因为我还有更多项目要添加到卡中,但是当我这样做时,屏幕只是空白吗?我曾尝试将其作为根(脚手架主体)放
我有一个带有窗体的 View ,该窗体显示ViewModel中ObservableCollection中对象的数据。 ObservableCollection使我可以浏览数据。 ObservableC
如何将时间戳附加文件名放在HDFS中? hadoop fs -put topic_2018-12-15%2016:31:15.csv /user/file_structure/ 最佳答案 您只是在运行
我正在寻求一些帮助,以找出为什么以下叠加函数的运行时间会随着每次连续运行而增加。 据我所知,如果缓冲区中的文本保持不变,则运行时间应该是相同的——即,仅向左/向右移动光标应该不会增加运行时间(但它确实
我有一个事件指示器,它显示在中间。如何将其放置在 View 的左上角? var activityIndicator = UIActivityIndicatorView() func show() {
首先,我想提前感谢所有回答这个问题的人。非常感谢您的帮助。这是我第一次在这里发帖,所以如果我发帖不礼貌,请原谅我。 我的问题是关于方法原型(prototype)的: void copySubtree(
我正在开发一个应该是通用的应用程序,一个适用于 iPad 和 iPhone 的应用程序。我想让他们的界面尽可能相似。在 iPhone 应用程序中,我使用的是选项卡栏 Controller ,其中一个选
我目前正在使用 JS 开发 REST API,但遇到以下问题:该代码有效,但如果我尝试删除、放置或修补不存在的条目,它不会返回错误,但会打印成功消息。这是为什么?获取路由完美运行。 app.route
.a{ width:500px; height:500px; background:yellow; border: 3px dashed black; }
首先,请引用下图: 这基本上是我对布局的想法。 我想要的是: 内容 div 成为“主要焦点”,例如当浏览器 调整大小,它应该留在中间; 当浏览器被调整大小时,我希望这两个图像基本上 位于内容 div
我的应用程序需要使用内存映射并发访问数据文件。我的目标是使其在共享内存系统中可扩展。研究了内存映射文件库实现的源码,想不通: 在多个线程中从 MappedByteBuffer 中读取是否合法? get
我有一个 JDesktopPane 并希望以网格样式显示 JInternalFrames 而无需覆盖框架。框架的尺寸会有所不同,因此应动态分配它们的位置。我可以存储最后放置的框架的坐标,但可以移动、最
根据https://isocpp.org/wiki/faq/dtors#placement-new传递给placement-new的地址必须正确对齐。但它给出的例子似乎与此相矛盾。 char memo
我最近一直在查看 Illumos 源代码,发现了一些奇怪的东西。 在他们的源代码中,函数类型是这样写的: static int outdec64(unsigned char *out, unsigne
您好,我目前正在尝试在我的一张图片旁边放置一个图例,但我在放置时遇到了问题。 我想将图例放在图像的左侧或右侧。这是我当前的代码: .my-legend .legend-title { text-a
根据文档, print 之间的唯一区别和 say 似乎是后者添加了 "\n"(并使用 .gist 进行字符串化)。然而, perl6 -e 'print "del\b\b"' 打印“d”,有效地应用转
所以我试图将我的图像标志放在背景上,但我的背景突然被裁剪,出现了一半的黑屏。如图: 我的 main.dart 代码: import 'package:flutter/material.dart'; i
我正在使用 Azure DevOps 构建 python 轮。我想让它尽可能通用,以便团队中的每个人都可以使用相同的管道来构建自己的 python 轮并将它们部署在一些 databricks 工作区中
在构建标准(非 WordPress)网页时,我通常会在正文末尾之前加载所有 javascript 文件,然后包含页面特定 js 代码的部分。 WorPress 建议使用 wp_enqueue_scri
我是一名优秀的程序员,十分优秀!