提交记录 13280


用户 题目 状态 得分 用时 内存 语言 代码长度
minstdfx router32. 测测你的路由器 Wrong Answer 50 185.712 ms 9720 KB C++ 1.30 KB
提交时间 评测时间
2020-08-01 09:34:53 2020-08-01 09:34:55
#include "router.h"

struct node{
	node *ch[2];
	unsigned nexthop;
	bool is_end;
	node () {
		ch[0]=ch[1]=0;
		is_end=false;
		nexthop=0u;
	}
}*rt;

inline unsigned _bit(unsigned a,unsigned k)//k in 0-31
{
	k=31-k;
	return a&(1<<k)>>(k);
}
inline void insert(char *bp,unsigned char len,unsigned nexthop,node *cur=rt)
{
	while(1){
		if(len==0)
		{
			cur->nexthop=nexthop;
			cur->is_end=true;
			break ;
		}
		++bp;
		--len;
		if(cur->ch[*bp]==0) cur->ch[*bp]=new node(); 
		cur=cur->ch[*bp];
	}
//	insert(bp+1,len-1,nexthop,((cur->ch[*bp]==0)?cur->ch[*bp]=new node:cur->ch[*bp]));
}
void init(int n, int q, const RoutingTableEntry *a) {
	rt=new node ();
	char bp[32];
	for(int i=0;i<n;++i)
	{
		for(unsigned char j=0;j<a[i].len;++j)
		{
			bp[j]=_bit(a[i].addr,1u*j);
		}
		insert(bp,a[i].len,a[i].nexthop);
	}
}
unsigned query(char *bp,unsigned char len,node *cur=rt)
{
	unsigned res=0;
	while(1)
	{
		if(rt->is_end)
		{
			res=rt->nexthop;
		}
		if(len==0)
		{
			break;
		}
		++bp;
		--len;
		if(cur->ch[*bp]==0) break;
		cur=cur->ch[*bp];
	}
	return res;
}
unsigned query(unsigned addr) {
	static char bp[32];
	for(unsigned char j=0;j<32;++j)
	{
		bp[j]=_bit(addr,1u*j);
	}
	return query(bp,32);
}

void del__(node *rt)
{
	if(rt==0) return;
	del__(rt->ch[0]);
	del__(rt->ch[1]);
	delete(rt);
	return ;
}
void del()
{
	del__(rt);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #111.44 us24 KBAcceptedScore: 25

Testcase #248.188 ms9 MB + 504 KBAcceptedScore: 25

Testcase #3116.953 ms9 MB + 504 KBWrong AnswerScore: 0

Testcase #4185.712 ms9 MB + 504 KBWrong AnswerScore: 0


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