提交记录 10890


用户 题目 状态 得分 用时 内存 语言 代码长度
skylines router32. 测测你的路由器 Accepted 100 292.321 ms 67756 KB C++11 1.30 KB
提交时间 评测时间
2019-10-09 16:56:12 2020-08-01 02:35:40
#include "router.h"
#include <arpa/inet.h>
struct Trie{
    struct node{
        node* son[2];
        unsigned via;
        node(){
            via=0;
            son[0]=nullptr;
            son[1]=nullptr;
        }
    };
    //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>>(31ul-i))&1ul;
            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 = root->via;
        bool x;
        for(int i=31;i>=0;i--)
        {
            x=addr>>i&1ul;
            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, const RoutingTableEntry *a){
    for(int i=0;i<n;i++){
        trie.insert(htonl(a[i].addr),a[i].len,a[i].nexthop);
    }
}
unsigned query(unsigned addr){
    return trie.query(htonl(addr));
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #111.96 us24 KBAcceptedScore: 25

Testcase #245.995 ms66 MB + 172 KBAcceptedScore: 25

Testcase #3169.433 ms66 MB + 172 KBAcceptedScore: 25

Testcase #4292.321 ms66 MB + 172 KBAcceptedScore: 25


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:12:35 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠