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

xiaoxiaole的更多相关文章

  1. 巨蟒python全栈开发-第15天 装饰器

    一.今日内容总览 关于函数的装饰器1.装饰器(重点,难点)(要求:反复写,代码不多但是很绕) 开闭原则:(比如,菜单是拆散的,一点点搞的,用友拆散自己的功能,以后就不用开发了) (1)对功能的扩展开放 ...

  2. day05-控制流程之if/while/for

    目录 控制流程之if判断 控制流程之while循环 控制流程之for循环 控制流程之if判断 if 其实就是根据条件来做出不同的反应,如果这样就这样干,如果那样就那样干 1. 如果:成绩 > 9 ...

随机推荐

  1. Java面向对象系列(6)- 封装详解

    封装 该露的露,该藏得藏 我们程序设计要追求"高内聚,低耦合".高内聚就是类得内部数据操作细节自己完成,不允许外部干涉:低耦合:仅暴露少量得方法给外部使用 封装(数据得隐藏) 通常 ...

  2. Jmeter系列(2)- 代理服务器录制脚本

    操作步骤 step-1 添加代理服务器 step-2 添加线程组 step-3 添加录制控制器 HTTP代理服务器配置 - HTTP(S) Test Script Recorder TestPlan ...

  3. 网络IO模型与Reactor模式

    一.三种网络IO模型: 分类: BIO 同步的.阻塞式 IO NIO 同步的.非阻塞式 IO AIO 异步非阻塞式 IO 阻塞和同步的概念: 阻塞:若读写未完成,调用读写的线程一直等待 非阻塞:若读写 ...

  4. javascript 中介者模式 mediator

    * player.js /** * 中介者模式 * @param {*} name 角色名称 * @param {*} teamColor 队伍颜色 */ function Player(name, ...

  5. html jquery操作

    $(document).on('事件','元素',function(参数){ // 函数体 }) 元素获取方式:https://www.cnblogs.com/lixiuran/p/5316727.h ...

  6. 51nod1355-斐波那契的最小公倍数【min-max容斥】

    正题 题目链接:http://www.51nod.com/Challenge/Problem.html#problemId=1355 题目大意 定义\(f_i\)表示斐波那契的第\(i\)项,给出一个 ...

  7. Ubuntu18.04安装MySQL教程

    Ubuntu18.04下安装MySQL 提示:以下操作均在root权限下进行. # 查看有没有安装MySQL: dpkg -l | grep mysql # 安装MySQL: apt install ...

  8. 安全通信协议SSH应用与分析

    一.实验简介: 本次实验属于安全协议应用与分析系列 二 实验环境: Windows server 2003 server windows xp 做client 三.实验目的 通过该实验了解SSH服务器 ...

  9. oracle扩展表空间

    1.  查看表空间的名字及文件所在的位置 select tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) tot ...

  10. Jave Hbase AP

    Hbase API 类和数据模型的对应关系 HBaseAdmin 类:org.apache.hadoop.hbase.client.HBaseAdmin 作用:提供了一个接口来管理 HBase 数据库 ...