xiaoxiaole
2024-09-07 15:05:49
common.cpp
#include "common.h"
common.h
#ifndef COMMON_H_INCLUDED
#define COMMON_H_INCLUDED
/*--------------------------------------*/
//0
#define NULL (0)
//1
#define getx(blockPos) ((blockPos>>4)&0b1111)
#define gety(blockPos) ((blockPos)&0b1111)
//2
#define getp(stateBlock) ((stateBlock>>16)&0b11111111)
#define getpu(stateBlock) ((stateBlock>>8)&0b11111111)
#define getpr(stateBlock) ((stateBlock)&0b11111111)
/*--------------------------------------*/
//2
typedef unsigned char BlockPos;
//3
typedef int StateBlock; /*--------------------------------------*/ /*--------------------------------------*/
#endif // COMMON_H_INCLUDED
hash.cpp
#include "hash.h"
/*--------------------------------------*/
//1
Trie g_hash;
/*--------------------------------------*/
//1
TrieNode::TrieNode()
{
this->s = 0;
this->next = NULL;
this->score = 0;
} //1
Trie::Trie()
{
TrieNode a;
this->layer0.push_back(a);
}
//2
bool Trie::isExited(vector<StateBlock> &v)
{
if (g_hash.layer0[0].next == NULL) return false; vector<TrieNode> *p = &g_hash.layer0; //point to vector layer 0
int target, tmpL, l, r, mid;
StateBlock tmps;
bool foundflg; int vL = v.size();
mid = 0;
for (int i=0; i<vL; ++i) {
p = (*p)[mid].next; //come to layer (i-1)
tmpL = (*p).size();
if (tmpL == 0) return false; //this layer is empty l = 0;
r = tmpL-1;
target = v[i];
foundflg = false;
while (l<=r) {
mid = ((l+r)>>1);
tmps = (*p)[mid].s;
if (tmps == target) { //find the target foundflg = true;
goto NEXT_LOOP;
}
else if (tmps < target) { //in second part
l = mid + 1;
} else { //in first part
r = mid - 1;
}
}
return false;
NEXT_LOOP:;
}
if ((*p)[mid].exiFlg == true) {
return true;
}
return false;
}
//3
bool Trie::addOneState(vector<StateBlock> &v)
{ }
hash.h
#ifndef HASH_H_INCLUDED
#define HASH_H_INCLUDED
/*--------------------------------------*/
#include "common.h"
/*--------------------------------------*/
#include "vector"
using namespace std;
/*--------------------------------------*/
//#define getStateExiFlg(StateBlock) (((StateBlock&0x8000)!=0)?1:0)
/*--------------------------------------*/
//1
class TrieNode {
public:
StateBlock s;
vector<TrieNode> *next;
int score; TrieNode();
}; //2
class Trie {
public:
vector<TrieNode> layer0; bool isExited(vector<StateBlock> &v);
bool addOneState(vector<StateBlock> &v); Trie();
};
/*--------------------------------------*/
//1
extern Trie g_hash;
/*--------------------------------------*/
//1 /*--------------------------------------*/
#endif // HASH_H_INCLUDED
main.cpp
#include "testfunc.h"
/*--------------------------------------*/
#include <iostream>
using namespace std;
/*--------------------------------------*/ int main()
{
hash_test1(); return 0;
}
testfunc.cpp
#include "testfunc.h"
#include "common.h"
#include "hash.h"
/*--------------------------------------*/
#include "stdio.h"
using namespace std;
/*--------------------------------------*/ //1
void hash_test1()
{ cout << g_hash.layer0
return;
}
testfunc.h
#ifndef TESTFUNC_H_INCLUDED
#define TESTFUNC_H_INCLUDED
/*--------------------------------------*/
//1
void hash_test1(); /*--------------------------------------*/
#endif // TESTFUNC_H_INCLUDED
最新文章
- 7-15ALL、 ANY、SOME子查询
- winmail服务器启动失败 无法启动
- (转)Ubuntu samba配置服务文件包
- Apache和tomcat服务器使用ajp_proxy模块
- rsync拉取远程文件
- trigger 触发器
- UVA 1344 Tian Ji -- The Horse Racing
- java日志概述和原理
- NOIP2013 D1T3 货车运输 zz耻辱记
- Nginx+Tomcat-cluster构建
- NOIP2016(D1T2)天天爱跑步题解
- Python自动化运维工具-Fabric部署及使用总结
- JS 动态生成JSON对象
- WPF解决按钮上被透明控件遮盖时无法点击问题
- BZOJ1068_压缩_KEY
- 洛谷P1106 删数问题
- hadoop https配置
- 安装fcitx
- Webdings和Wingdings字符码对应表
- [BZOJ 3140] 消毒
热门文章
- scrum项目冲刺_day10总结
- RE Validation in JavaEE
- css 限制字数
- 哪5种IO模型?什么是select/poll/epoll?同步异步阻塞非阻塞有啥区别?全在这讲明白了!
- 前端常用场景总结CSS/JS/插件(实用篇更新中...)
- 解决Windows 游戏 错误代码 1170000
- ggplot2 画图随笔
- CF960G-Bandit Blues【第一类斯特林数,分治,NTT】
- Phalcon如何创建多模块并能进行访问 《Phalcon入坑指南系列 四》
- MyBatis封装对象内的List出现的问题