提交记录 10883


用户 题目 状态 得分 用时 内存 语言 代码长度
skylines router32. 测测你的路由器 Compile Error 0 0 ns 0 KB C++11 1.16 KB
提交时间 评测时间
2019-10-09 16:19:27 2020-08-01 02:34:41
#include "router.h"
struct Trie{
    struct node{
        node* son[2];
        unsigned via;
    };
    const int id[32]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,23,22,21,20,19,18,17,16,31,30,29,28,27,26,25,24};
    node *root;
    void insert(unsigned addr,int len,unsigned nxt){
        if(root==nullptr)
        {
            root = new node();
        }
        node *tmp=root;
        bool x;
        for(int i=0;i<len;i++)
        {
            x=addr>>id[i]&1;
            cout<<x<<endl;
            if(tmp->son[x]==nullptr)
                tmp->son[x] = new node();
            tmp=tmp->son[x];
        }
        tmp->via=nxt;
    }
    unsigned query(unsigned addr){
        node *tmp=root;
        unsigned ans = 0;
        bool x;
        for(int i=0;i<32;i++)
        {
            x=addr>>id[i]&1;
            if(tmp->son[x]==nullptr) return ans;
            tmp=tmp->son[x];
            if(tmp->via!=0)
                ans=tmp->via;
        }
        return ans;
    }
}trie;
void init(int n, int q, RoutingTableEntry *a){
    for(int i=0;i<n;i++){
        trie.insert(a[i].addr,a[i].len,a[i].nexthop);
    }
}
unsigned query(unsigned addr){
    return trie.query(addr);
}

CompilationN/AN/ACompile ErrorScore: N/A


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-28 18:40:45 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠