- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好的,我的任务是使用一种方法 (IU) 比较此光子列表并将其与另一种方法 (TSP) 进行比较。我需要获取第一个 IU 光子并将距离与 所有 的 TSP 光子进行比较,找到最小距离,然后将它们“配对”(即将它们都设置在具有相同索引的数组中)。然后,我需要获取 IU 列表中的下一个光子,并将其与所有 TSP 光子进行比较,减去已经选择的光子。我知道我需要使用各种 bool 数组,并保留一个计数器。我似乎无法完全理解它。
下面的代码不是标准的 C++ 语法,因为它是为与 ROOT(CERN 数据分析软件)交互而编写的。如果您对语法有任何疑问以更好地理解代码,请提问。我会很乐意回答。
我已经声明了数组和变量。您看到的类型称为 EEmcParticleCandidate,它是一种从信息树中读取的类型,我有一整套类和 header 来指示其行为方式。
谢谢。
Bool_t used[2];
if (num[0]==2 && num[1]==2) {
TIter photonIterIU(mPhotonArray[0]);
while(IU_photon=(EEmcParticleCandidate_t*)photonIterIU.Next()){
if (IU_photon->E > thresh2) {
distMin=1000.0;
index = 0;
IU_PhotonArray[index] = IU_photon;
TIter photonIterTSP(mPhotonArray[1]);
while(TSP_photon=(EEmcParticleCandidate_t*)photonIterTSP.Next()) {
if (TSP_photon->E > thresh2) {
Float_t Xpos_IU = IU_photon->position.fX;
Float_t Ypos_IU = IU_photon->position.fY;
Float_t Xpos_TSP = TSP_photon->position.fX;
Float_t Ypos_TSP = TSP_photon->position.fY;
distance_1 = find distance //formula didnt fit here //
if (distance_1 < distMin){
distMin = distance_1;;
for (Int_t i=0;i<2;i++){
used[i] = false;
} //for
used[index] = true;
TSP_PhotonArray[index] = TSP_photon;
index++;
} //if
} //if thresh
} // while TSP
} //if thresh
} // while IU
这就是我目前所拥有的...正在进行中,我意识到所有的牙套都没有闭合。这只是一道简单的逻辑题。
最佳答案
这可能需要几次迭代。
作为粒子物理学家,您应该了解将事物分解成其组成部分的重要性。让我们从遍历所有 TSP 光子开始。看起来好像相关代码在这里:
TIter photonIterTSP(mPhotonArray[1]);
while(TSP_photon=(EEmcParticleCandidate_t*)photonIterTSP.Next()) {
...
if(a certain condition is met)
TSP_PhotonArray[index] = TSP_photon;
}
因此 TSP_photon
是一个指针,您将把它复制到数组 TSP_PhotonArray
中(如果光子的能量超过固定阈值),然后您将转到跟踪哪些指针已经被复制了很多麻烦。有更好的方法,但现在我们只考虑寻找最佳匹配的问题:
distMin=1000.0;
while(TSP_photon= ... ) {
distance_1 = compute_distance_somehow();
if (distance_1 < distMin) {
distMin = distance_1;
TSP_PhotonArray[index] = TSP_photon; // <-- BAD
index++; // <-- VERY BAD
}
}
这是错误的。 假设您找到了一个距离最小的 TSP_photon。您还没有检查所有 TSP 光子,所以这可能不是最好的,但您无论如何都存储指针,并增加索引。然后,如果您发现另一个更好的匹配项,您也会存储那个匹配项。从概念上讲,它应该是这样的:
distMin=1000.0;
best_photon_yet = NULL;
while(TSP_photon= ... ) {
distance_1 = compute_distance_somehow();
if (distance_1 < distMin) {
distMin = distance_1;
best_pointer_yet = TSP_photon;
}
}
// We've now finished searching the whole list of TSP photons.
TSP_PhotonArray[index] = best_photon_yet;
index++;
对这个答案发表评论,告诉我这是否有意义;如果是,我们可以继续,如果不是,我会尽力澄清。
关于c++ - 逻辑帮助 : comparing values and taking the smallest distance, 同时从 "available to compare"列表中删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11295065/
我有一个代表每个年龄段的人口(M,F)的集合。 为了通过时间来预测人口,我必须首先对女性进行计算,以便我可以根据男性出生率的统计常数来计算新出生的男性和女性的百分比。 也就是说,我有一个包含每岁男性和
我正在尝试从队列中获取 n 条消息(使用 langohr)。我有一个工作版本,但我想知道是否有更好的 clojurist 方法来做到这一点: (def not-nil? (complement nil
我有这些结果用于分析一个简单的查询,该查询不会从少于 200 条记录的表中返回超过 150 条记录,因为我有一个存储最新值的表,而其他字段是数据的 FK . 更新:稍后查看同一查询的新结果。该网站未公
我正在使用 .Take() 来获取固定数量的结果。 获取 TotalCountBeforeTake 的最佳方法是什么(即好像我没有使用 .Take())? 我可以在不运行查询两次的情况下获得 Tota
我有一个 BatchConfigurable 类 public class BatchConfigurable() {} 我正在尝试为其编写一个包装器。这将是另一个类,它采用此类或任何扩展 Batch
byte[] result = memStream.ToArray(); memStream.Close(); byte[] temp = r
很简单的问题。我有一个值列表,我想用空值填充这些值,这样我总是会返回 X 个项目。 List list = new List() { 10, 20, 30 }; IEnumerable values
我正在构建一个购物车,并且我使用了一个购物车服务,在该服务中我将数量分配给产品/将产品添加到购物车。除了使用 take 获取可观察项 $ 的第一个实例之外,还有其他方法吗? 我正在正确导入 take
这是欧拉计划的问题 8。 我试图通过数字数组foreach,每次跳过最后一个数字并拉接下来的13个相邻数字数组。 我的代码: for(int x = 0; x product) {
我有 3 个 div 元素,一个是父元素,另外两个是子元素: dinesh pathak and their css are: #table {
我在 Hudson 上发现了异常行为。Hudson 作业大约需要 25 分钟,而当我在本地运行相同的作业时,需要 9 分钟。我在这里缺少什么? 我增加了 JAVA_OPTS、MAVEN_OPTS,甚至
let a = [1;2;3;] for i in (a |> Seq.take 10) do Console.WriteLine(i) for i in (a |> Seq.take 100) do
我正在尝试编写一些 LINQ To SQL 代码来生成类似 SQL 的代码 SELECT t.Name, g.Name FROM Theme t INNER JOIN ( SELECT TOP
给定这样的设置.. class Product { int Cost; // other properties unimportant } var products = new List
我有一个 List 类型的元素 public class FriendList { public List friends { get; set; } // List
给定以下 LINQ 语句,哪个更有效? 一个: public List GetLatestLogEntries() { var logEntries = from entry in db.Lo
我只是在尝试新的 kotlin 语言。我遇到了生成无限列表的序列。我生成了一个序列并尝试打印前 10 个元素。但是下面的代码没有打印任何东西: fun main(args: Array) {
我见过 sagas 以 3 种方式监听 Action : 1。 while(true) take() function* onUserDetailsRequest() { while(true)
假设我有一些神奇的分页黑盒类,它使用 pageIndex 和 pageSize 检索数据,如下所示: public class PaginatedList { // ... // Ch
我有两个 git 分支 b' 和 b" 具有完全相同的 SHA-1 和因此内容。我提交 b ' 并在提交时,我使用 -x 应用 cherry-pick 而不是 merge 或 rebase单个提交到我
我是一名优秀的程序员,十分优秀!