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. php时间区间,优化显示

    <?php /** * 类似微信的时间显示 * 规则是:今天的,显示几秒前,几分钟前,几小时前,昨天的显示昨天 上午 XX:XX * 再往前,本周的,显示周几+时间,再往前,本年的,显示月日+时 ...

  2. nuxt打包等注意事项

    打包步骤: 1.首先执行 npm run build 2.将打包好的 .nuxt static nuxt.config.js package.json 这四个文件丢到服务器的某个文件夹中,在服务器上安 ...

  3. TP5 数据保存、更新问题(save、saveAll)

    一.今天写项目的时候,突然发现一个坑爹的问题,使用saveAll新增多条数据,但是一直提示缺少更新条件,然而我发现代码里面并没有更新,而且saveAll我仅仅是去新增多条数据而已 原来源码 模型类中有 ...

  4. Linux系列(1) - 使用Hyper-V安装Linux系统

    前言 使用工具:Hyper-V,补充:hyper-v是一项技术,而vmware是一款软件.具体区别自行百度 LINUX版本:CentOS-8.4.2105-x86_64-dvd1.iso Window ...

  5. sunny 内网穿透使用。

    启动方法:

  6. CF235C-Cyclical Quest【SAM】

    正题 题目链接:https://www.luogu.com.cn/problem/CF235C 题目大意 一个文本串\(s\).询问\(n\)个匹配的本质不同的循环同构在文本串中出现了几次. 解题思路 ...

  7. P3343-[ZJOI2015]地震后的幻想乡【dp,数学期望】

    正题 题目链接:https://www.luogu.com.cn/problem/P3343 题目大意 给出\(n\)个点的一张无向图,每条边被修复的时间是\([0,1]\)的一个随机实数,求这张图联 ...

  8. Decorator装饰器模式个人理解

    对于装饰器模式,其主要是为了:在不改变本体特征的情况下,对其进行包装.装饰,目的是为了补充.扩展.增强其功能. 有三个原则: 不能改变本体的特征 要对本体的功能进行扩展 装饰器脱离了本体则没有任何含义 ...

  9. Redis三种集群模式介绍

    三种集群模式 redis有三种集群模式,其中主从是最常见的模式. Sentinel 哨兵模式是为了弥补主从复制集群中主机宕机后,主备切换的复杂性而演变出来的.哨兵顾名思义,就是用来监控的,主要作用就是 ...

  10. ajax 中文参数乱码问题不一定是编码格式问题。

    代码要修改用户的信息,写了三个ajax,第一个写完测试没有问题,后面俩逻辑一样的就直接复制粘贴了.到第二个ajax测试的时候发现中文会乱码 如下 $.ajax({//中文参数乱码 url: '/edi ...