提交记录 14330


用户 题目 状态 得分 用时 内存 语言 代码长度
zhangzj router32. 测测你的路由器 Compile Error 0 0 ns 0 KB C++ 964 B
提交时间 评测时间
2020-09-23 16:06:47 2020-09-23 16:06:49
#include "router.h"
#include <arpa/inet.h>
#include <hash_map>

unsigned nexthop_trie[17000000] = {0};
std::hash_map <unsigned, unsigned> hashmap;

void init(int n, int q, const RoutingTableEntry *a) {
    for (int i = 0; i < n; i++)
    {
        unsigned addr = a[i].addr;
        if (a[i].len == 32)
            hashmap[a[i].addr] = a[i].nexthop;
        else
        {
            int cnt = 0;
            for (int l = len; l > 0; l -= 8)
            {
                cnt = (cnt << 8) + (addr & 255) + 1;
                addr >>= 8;
            }
            nexthop_trie[cnt] = a[i].nexthop;
        }
    }
}

unsigned query(unsigned addr) {
    if (hash_map.find(addr) != hash_map.end())
        return hash_map[addr];
    int ret = 0;
    int cnt = 0;
    for (int l = 24; l > 0; l -= 8)
    {
        cnt = (cnt << 8) + (addr & 255) + 1;
        addr >>= 8;
        if (nexthop_trie[cnt] != 0)
            ret = nexthop_trie[cnt];
    }
    return ret;
}

CompilationN/AN/ACompile ErrorScore: N/A


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