Build Tree

轻松编写高效工具类:构建树形结构的秘籍 在软件开发中,树形结构是一种常见且重要的数据结构。它以树的形式组织数据,其中每个节点可以包含任意数量的子节点。树形结构广泛应用于各个领域,如文件系统、图像处理、网站导航等。树形结构的主要优势在于能够以递归方式组织和访问数据。它提供了一种直观、灵活的方式来表示层次关系,并且能够高效地执行插入、删除和搜索操作。树形结构对于处理包含父子关系的数据非常有用,它能够轻松地表示层级结构和组织结构,使得数据操作更加方便和高效。然而,手动构建树形结构往往复杂且繁琐。需要考虑节点的层级关系、递归处理节点和节点列表等问题。 阅读详情

题目描述:

You need to construct a full n-ary tree(n叉树) with m layers.All the edges in this tree have a weight.But this weight cannot be chosen arbitrarily you can only choose from set S,the size of S is k,each element in the set can only be used once.Node 0 is the root of tree.

We use d(i) for the distance from root to node i.Our goal is to minimize the following expression:

min∑i=0Nd(i)

Please find the minimum value of this expression and output it.Because it may be a big number,you should output the answer modul p.

输入:

The input file contains 2 lines.

The first line contains 4 integers,these respectively is k,m,n,p。(2 ≤ k ≤200000,2 ≤ p≤ 1015)

The second line contains k integers,represent the set S,the elements in the set guarantee less than or equal to 1015.

We guarantee that k is greater than or equal to the number of edges.

输出:

The output file contains an integer.represent the answer.

样例输入:

5 2 3 10
1 2 3 4 5

样例输出:

6

题目大意是,给出n叉树,并给出层数,要求在以下的数字集合中选出数字,组成满n叉树,使得每一个结点到根节点的距离之和最大
根据贪心策略,使总距离最大,那么应该将较小的边放在尽可能靠前的位置
代码如下:

#include<stdio.h>
#include<string.h>
#include<algorithm>
long long a[300000]; 
long long s[300000];
int main()
{
	long long k,n,m,p;
	while(~scanf("%lld%lld%lld%lld",&k,&m,&n,&p))
	{
		int i,j;
		memset(a,0,sizeof(a));
		memset(s,0,sizeof(s));
		for(i=0;i<k;i++)
		{
			scanf("%lld",&a[i]);
		}
		std::sort(a,a+k);
		int ceng=n;
		int count=0;
		for(i=2;i<=m;i++)
		{
			s[i]=(s[i-1]*n)%p;
			for(j=0;j<ceng;j++)
			{
				s[i]=(s[i]+a[count++])%p;
			}
			ceng=ceng*n;
		}
		long long sum=0;
		for(i=2;i<=m;i++)
		{
			sum=(sum+s[i])%p;
		}
		printf("%lld\n",sum);
	}
	return 0;
}
对PCL中build_tree.cpp的的学习与解释 对PCL中build_tree.cpp的的学习与解释 从主函数main开始阅读 首先是命令行参数,执行 “$ ./build/build_tree data/” 前一字符串为项目运行的所在位置,后一个字符串是pcd文件的位置 如果改在VS2017中运行,可以直接注释掉93到97行代码,并将109行的loadFeatureModels中的第一个参数直接设定为文件位置 loadFeatureModels("data/", extension, models); 第99和100行代码,添加了文件名后缀 使用st 阅读详情

相关推荐

从URDF到Gazebo:一个完整的ROS2机械臂仿真项目实战与避坑指南

本文提供了一个完整的ROS2机械臂仿真项目实战指南,详细讲解了从URDF建模、ROS2 Control配置、MoveIt2集成到Gazebo仿真的全流程。文章重点分享了URDF惯性参数设置、Gazebo插件选择、MoveIt2配置修正等关键步骤的避坑经验,帮助开发者快速搭建可用的六轴机械臂仿真环境,实现从静态模型到物理仿真的跨越。

weixin_29279153的博客 274

B - Build Tree

这里写目录标题B - Build Tree B - Build Tree You need to construct a full n-ary tree(n叉树) with m layers.All the edges in this tree have a weight.But this weight cannot be chosen arbitrarily you can only choose from set S,the size of S is k,each element in the set

J_JL_L的博客 339

机械臂速成小指南(八):标准DH法实战——从连杆坐标系到运动学方程

本文详细介绍了机械臂运动学建模中的标准DH法,从连杆坐标系的建立到运动学方程的求解,提供了实用的操作步骤和代码示例。通过DH参数表和变换矩阵的构建,帮助读者快速掌握机械臂运动学建模的核心技术,并解决实际应用中的常见问题。

oo7890的博客 211

java-buildTree生成树实现

【代码】java-buildTree生成树实现。

blns_yxl的博客 927

C# MES通信从入门到精通(10)——C#使用HTTP的Post和Get方法和Mes系统通信

本文详细介绍了如何利用C#完成与HTTP协议的MES系统进行通信,通过POST和GET方法实现与MES系统的交互,由高级工程师的实战经验总结,实属C#与MES通信领域的葵花宝典!

qq_34059233的博客 3413

【PCIe EP 设备入门学习专栏 -- 8 PCIe EP 架构详细介绍】

Synopsys PCIe 5.0 EP 架构由多个功能模块组成,整体遵循分层 + 模块化设计CXPL(事务层 + 链路层 + 物理层 MAC)XADM(仲裁/生成)、XAIM(应用接口)RADM(过滤/路由/Completion)CDM(配置空间)、PMC(电源管理)、LBC/DBI(寄存器访问)MSG_GEN(消息)、CXS(多芯片一致性)

CodingCos的博客 382

java buildtree_java树结构工具类TreeBuilder和TreeUtil

package cloud.simple.service.util;import java.util.ArrayList;import java.util.List;import cloud.simple.service.dto.TreeNode;public class TreeBuilder {/*** 使用递归方法建树* @param treeNodes* @return*/public s...

weixin_33609486的博客 1334

【异常】Cursor IDE 扩展主机超时错误处理文档The agent execution provider did not respond within 4 seconds.

该错误通常是 Cursor IDE 的临时性问题,不影响项目代码。大多数情况下,重新加载窗口或重启 IDE 即可解决。如果问题持续,可按上述进阶方案排查。重新加载窗口(最快)重启 IDE检查系统资源清理缓存检查扩展更多关于 AI+教育领域的干货,可以关注我的微信公众号第一时间获取哦~

奶爸的编程之路,也就一周冷个三天 2700

Build Tree (HDU 6533)

题目:Build Tree 思路:类似于哈夫曼树的贪心想法,先将消耗大的离根更近一些,当计算当前边权时,统计它下面的所有子节点数再加上它本身,就是这条边在所有子节点到根节点的路径上出现的数目 #include<iostream> #include<algorithm> #include<cstdio> #include<cmath> using namespace std; typedef long long LL; const int N=2e5+5; i

weixin_45758110的博客 367

【笔记篇】Davinci Configurator BswM模块

AUTOSAR BSWM模块配置介绍

weixin_47571898的博客 1534

Python 爬虫实战:深入同花顺,抓取股票行情数据,助力投资决策

通过本次 Python 爬虫实战,我们成功地从同花顺抓取了股票行情数据,并进行了存储、处理、分析和可视化展示。在这个过程中,我们不仅掌握了爬虫技术的基本应用,还学会了如何对动态加载的数据进行处理和分析。然而,本次爬虫任务也存在一些局限性,例如仅爬取了部分股票的数据,且未对股票的历史行情进行深入分析。在未来的工作中,我们可以进一步优化爬虫程序,爬取更多股票的数据,并深入分析股票的历史行情走势、技术指标等,为投资者提供更有价值的数据支持。

u014481728的博客 5334

Ext tree build

Ext tree build 320K

xieaiji的专栏 120

超分辨率重建:ESPCN与SRGAN技术对比

超分辨率重建:ESPCN与SRGAN技术对比​ 人工智能,计算机视觉,大模型,AI,超分辨率重建是一种通过技术手段,将低分辨率图像转换为高分辨率图像的过程。它的目的是恢复低分辨率图像中丢失的细节信息,使图像具有更高的清晰度和视觉质量。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 7万+

npm run build 出现dependency tree错误

问题 运行 npm run build 进行编译时出现 dependency tree 错误。原因由于上层目录也有node_module,且安装了webpack 导致依赖找不到,编译失败 Error.png 解决方法 1、根据错误提示如果忽略此检查,可以在.env 文件中添加 SKIP_PREFLIGHT_CHECK=true 来忽略此检查。 在文件根目录下添加.env文件,然后写入SK...

Evita 226

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Segment Tree Build

The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval. start and end are both integers, they should be assigned in following r

ass673556617的专栏 306

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

2019CCPC湘潭全国邀请赛 B:Build Tree(树)

【题面】 Build Tree 【题解】 题意:给定一个m层满n叉树和k条边的权值,N表示所需的边的数目,di表示结点i到根结点的距离,输出。 思路:计算每个结点到根结点的距离即父节点到根结点的距离+结点到父节点的距离,并求和取模即可。 【代码】 #include <bits/stdc++.h> using namespace std; const int maxn...

菜鸡成长史 1190

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

build tree

http://ocaicai.iteye.com/blog/1047397

kingoverlord的专栏 2286

Expression Tree Build

Description: The structure of Expression Tree is a binary tree to evaluate certain expressions. All leaves of the Expression Tree have an number string value. All non-leaves of the Expression Tr...

banhua3000的博客 140

HDUOJ 6533 Build Tree

HDUOJ 6533 Build Tree 题目链接 Problem Description You need to construct a full n-ary tree(n叉树) with m layers.All the edges in this tree have a weight.But this weight cannot be chosen arbitrarily you can only choose from set S,the size of S is k,each element i

旺崽的博客 2807

Lintcode - Segment Tree Build

The structure of Segment Tree is a binary tree which each node has two attributes start andend denote an segment / interval. start and end are both integers, they should be assigned in following

雯雯熊孩子 1580

Segment Tree Build II

The structure of Segment Tree is a binary tree which each node has two attributes start and end denote an segment / interval. start and end are both integers, they should be assigned in following r

ass673556617的专栏 496
上一篇: Elven Postman
下一篇: 二叉搜索树
大橘为重eleven
博客等级 码龄8年 35粉丝 103原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值