#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
    
相关推荐
Warson_L2 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅2 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅2 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L3 小时前
python的类&继承
python
Warson_L3 小时前
类型标注/type annotation
python
ThreeS5 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵7 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏