#P3492.第1题-基于决策树预判资源调配优先级

第1题-基于决策树预判资源调配优先级 - problem_ide - CodeFun2000

主要是把题看懂

python 复制代码
class Node:
    def __init__(self,feature_index,threshold,left,right,label):
        self.feature_index = feature_index
        self.threshold = threshold
        self.left = left
        self.right =right
        self.label =label


f,m,n = map(int,input().split())

tree = []

for _ in range(m):
    fi,thr,l,r,lbl = input().split()

    tree.append(Node(int(fi),float(thr),int(l),int(r),int(lbl)))

for _ in range(n):
    features = list(map(float,input().split()))

    current = 0

    while True:
        node = tree[current]
        if node.feature_index == -1:
            print(node.label)
            break
        
        if features[node.feature_index] <= node.threshold:
            current = node.left
        else:
            current = node.right
    
相关推荐
copyer_xyf16 分钟前
Python 模块与包的导入导出
前端·后端·python
8Qi833 分钟前
LeetCode 213:打家劫舍 II(House Robber II)—— 题解 ✅
算法·leetcode·职场和发展·动态规划
ice81303318141 分钟前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
三品吉他手会点灯41 分钟前
C语言学习笔记 - 44.运算符和表达式 - 运算符2 - 除法与取余运算符
c语言·开发语言·笔记·算法
copyer_xyf42 分钟前
Python venv 虚拟环境
前端·后端·python
乐迪信息1 小时前
乐迪信息:AI算法盒子实时识别船舶烟雾与火焰异常
大数据·人工智能·算法·安全·目标跟踪
J-Tony111 小时前
【JVM】根可达算法
jvm·算法
艾iYYY1 小时前
string 类的模拟实现
android·服务器·c语言·c++·算法
Lsk_Smion2 小时前
力扣实训 _ [75].颜色分类 _ 杨辉三角
数据结构·算法·leetcode