Frenemies题解搜索DFS

本文介绍了一种基于递归深度优先搜索(DFS)的算法,用于解决特定类型的敌友关系问题。通过计算从一个人到其他人所有可能路径上的权值之和来确定他们之间的总体关系分数。文章提供了一个详细的代码实现案例。

http://zuojie.3322.org:88/soj/problem.action?id=3730

3730: Frenemies

Submit your solution     Discuss this problem     Best solutions
Time Limit: 3000 MS    Memory Limit: 65536 K 


 

Description

You may have heard the expression "the enemy of my enemy is my friend". By extension, then, "the enemy of my enemy of my enemy is my enemy", and so on. Given a set of relationships, you wish to determine how much of a friend or enemy people are, represented by a "total relationship score".

Input

Input to this problem will begin with a line containing a single integer N (1 ≤ N ≤ 100) indicating the number of data sets. Each data set will consist of a series of lines. The first line will contain a single integer P (1 ≤ P ≤ 9) specifying the number of people in this data set. The next P lines will contain a relationship matrix that describes direct relationships between each person in the format "Name R1 R2 ... RX ... RP", with Name being a unique name for a person consisting of up to twenty contiguous alphanumeric characters and RX indicating the relationship that exists between this person and person X, with "F" representing a friend, an "E" representing an enemy, and "N" representing a neutral relationship. For example, if a line contained "Bob F E N", this would indicate that Bob is friends with the person on the first line of the relationship matrix, enemies with the person on the second line of the relationship matrix, and has a neutral relationship with the person on the third line of the relationship matrix. Note that a person will always have a neutral relationship with themselves and that relationships are bi-directional (e.g., if Bob is a friend with George, then George is a friend with Bob). The last line in the data set will contain a single name for which the total relationship scores between that person and every other person are to be computed.

Output

For each data set, print a single line containing the total relationship scores between the name given in the final line of the data set and every other person in the data set, with each score separated by a single space and in the same order that the names appear in the input. The total relationship score between two people is the sum total of all the relationship scores of direct and indirect relationships between them. Direct relationships are determined by the input described above. Indirect relationships are those in which a cycle-free path of two or more relationships can be traced between two people, with none of those relationships being of the neutral variety (e.g., an "enemy of an enemy" or an "enemy of a friend of an enemy"). The formula for determining a direct or indirect relationship score is as follows: where x is the number of enemy relationships in the path and y is the total number of relationships in the path. Some examples follow: Also note that the total relationship score of a person with themselves is 0.

Sample Input

3 5 Bob N F E N N Friend F N N N N Enemy E N N F E FriendOfEnemy N N F N N EnemyOfEnemy N N E N N Bob 4 Bob N F F F Tom F N E E Tim F E N F Joe F E F N Bob 4 Spy1 N E F N Spy2 E N E N Spy3 F E N N Spy4 N N N N Spy3

Sample Output

0 128 -128 -64 64 0 -64 128 128 192 -192 0 0
就是求一点到所有点的经过的路径的权值和
简单的DFS回溯,刚开始还以为是Floyd
后来发现是搜索,数据测试正确,但是一直WA
比赛结束后,发现错在我标记边为已经访问,其实应该标记点为已经访问
很久没做搜索题了,这么简单的错误都犯。故写下此题解警戒。
题解:
对于给点的点对其它每一个点做一次回溯搜索,
访问所有可以从起点到目标点的路径,把权值求和。
 
农业作物成熟度实例分割数据集 一、基础信息 • 数据集名称:农业作物成熟度实例分割数据集 • 图片数量: 训练集:563张图片 验证集:161张图片 测试集:80张图片 总计:804张图片 • 训练集:563张图片 • 验证集:161张图片 • 测试集:80张图片 • 总计:804张图片 • 分类类别: bfullyripened: b类作物完全成熟状态 bgreen: b类作物绿色未成熟状态 bhalfripened: b类作物半成熟状态 lfullyripened: l类作物完全成熟状态 lgreen: l类作物绿色未成熟状态 lhalfripened: l类作物半成熟状态 • bfullyripened: b类作物完全成熟状态 • bgreen: b类作物绿色未成熟状态 • bhalfripened: b类作物半成熟状态 • lfullyripened: l类作物完全成熟状态 • lgreen: l类作物绿色未成熟状态 • lhalfripened: l类作物半成熟状态 • 标注格式:YOLO格式,包含实例分割多边形点标注,适用于实例分割任务。 • 数据格式:图片来源于农业图像数据库,细节清晰,适用于模型训练。 二、适用场景 • 农业AI监测系统开发:数据集支持实例分割任务,帮助构建能够自动识别作物部分并分类成熟度的AI模型,辅助农民进行精准农业管理。 • 精准农业应用研发:集成至农业智能平台,提供实时作物状态识别功能,优化灌溉、施肥和收获时间。 • 学术研究与创新:支持农业科学与人工智能交叉领域的研究,助力发表高水平农业AI论文。 • 农业教育与培训:数据集可用于农业院校或培训机构,作为学生学习作物识别和成熟度评估的重要资源。 三、数据集优势 • 精准标注与多样性:每张图片均经过精确标注,确保实例分割边界准确,类别分类正确。涵盖两种作物类型(b和l)和三种成熟度状态(完全成熟、绿色未成熟、半成熟),具有高度多样性,提升模型泛化能力。 • 任务适配性强:标注兼容主流深度学习框架(如YOLO等),可直接加载使用,支持实例分割任务,并可扩展到其他计算机视觉任务。 • 农业价值突出:专注于作物成熟度检测,为智能农业、自动化收获和作物健康监测提供关键数据支持,具有重要的实际应用价值。
本资源包提供了针对STM32F103C8微控制器的MPU6050加速度计和陀螺仪的软件I2C驱动程序。通过集成数字运动处理(DMP)技术,能够实现高精度的姿态解算,适用于需要实时感知设备方向和动作的应用场景。此驱动还支持OLED显示屏,直接在设备上展示姿态信息,如俯仰、滚转和偏航角度,非常适合飞行器、机器人或是任何需要姿态监测的项目。 主要特点 软件I2C实现:无需专用的硬件I2C接口,适用于资源有限的STM32F103C8开发板。 DMP姿态解算:利用MPU6050内置的DMP,提供准确的姿态估计。 OLED显示集成:可以直接在OLED屏幕上显示加速度和角速度等姿态数据,便于实时监控。 兼容性说明:已验证与匿名地面站通信协议6.0版本兼容,特别适合与V6.56版本的地面站软件配合使用。 示例代码:包含完整的演示代码,方便用户快速上手并进行二次开发。 使用指南 环境配置:确保你的开发环境支持STM32F103C8,推荐使用STM32CubeIDE或Keil uVision等IDE。 库文件导入:将提供的源码文件夹导入到你的工程中。 配置I2C和OLED:根据你具体的硬件连接调整I2C引脚配置及OLED初始化设置。 连接MPU6050:按照电路图正确连接MPU6050传感器至STM32F103C8的I2C线路上。 编译与调试:编译项目,并通过ST-LINK或其他编程器将固件烧录到STM32F103C8。 测试与应用:运行程序,观察OLED屏幕上的姿态数据显示,可通过匿名地面站软件进行远程监控(需符合通信协议)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值