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. win10连接mysql提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    win10中cmd连接mysql提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YE ...

  2. Java对象构造

    关于对象构造的一些认识. 默认域初始化 如果在构造器中没有显示地给域赋予初值,那么就会被自动地赋予默认值:数值为0,布尔值为false,对象引用为null.然而,这显然是不安全的,在一个null引用上 ...

  3. HTML 网页开发、CSS 基础语法——八.HTML基本语法

    表格制作 1.表格基础 创建一个简单的表格至少有三个标签组成,分别是<table>,<tr>,<td>标签. table:表格,定义的是整个的表格大结构. tr:t ...

  4. CF235C-Cyclical Quest【SAM】

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

  5. Python3入门系列之-----内置的文件操作模块OS

    前言 在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路径进行操作,这个时候就需要用到os模块. 使用前 ...

  6. iOS 15 无法弹出授权弹框之解决方案---Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0

    2021年9月30日下午:我正愉快的期盼着即将到来的国庆假期,时不时刷新下appstoreconnect的网址,28号就提上去的包,今天还在审核中....由于这个版本刚升级的xcode系统和新出的iO ...

  7. 3-等待线程终止的join方法

    等待线程终止的join方法 在项目实践中经常会遇到一个场景,就是需要等待某几件事完成之后才能继续往下执行,比如线程加载资源等等. package com.heiye.learn1; public cl ...

  8. 【C++ Primer Plus】编程练习答案——第10章

    1 // chapter10_1_account.h 2 3 #ifndef LEARN_CPP_CHAPTER10_1_ACCOUNT_H 4 #define LEARN_CPP_CHAPTER10 ...

  9. 踩坑系列《二》NewProxyResultSet.isClosed()Z is abstract 报错踩坑

    在运行测试类的时候莫名其妙的报了个 NewProxyResultSet.isClosed()Z is abstract 这个错误,之前出现过这个错误,以为是版本出现了问题 就将版本 0.9.1.2 改 ...

  10. 把之前CompletableFuture留下的坑给填上。

    你好呀,我是歪歪. 填个坑吧,把之前一直欠着的 CompletableFuture 给写了,因为后台已经收到过好几次催更的留言了. 这玩意我在之前写的这篇文章中提到过:<面试官问我知不知道异步编 ...