xiaoxiaole
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的更多相关文章
- 巨蟒python全栈开发-第15天 装饰器
一.今日内容总览 关于函数的装饰器1.装饰器(重点,难点)(要求:反复写,代码不多但是很绕) 开闭原则:(比如,菜单是拆散的,一点点搞的,用友拆散自己的功能,以后就不用开发了) (1)对功能的扩展开放 ...
- day05-控制流程之if/while/for
目录 控制流程之if判断 控制流程之while循环 控制流程之for循环 控制流程之if判断 if 其实就是根据条件来做出不同的反应,如果这样就这样干,如果那样就那样干 1. 如果:成绩 > 9 ...
随机推荐
- 274 day04_Map,斗地主案例
day04 [Map] 主要内容 Map集合 教学目标 [ ] 能够说出Map集合特点 [ ] 使用Map集合添加方法保存数据 [ ] 使用"键找值"的方式遍历Map集合 [ ...
- vijos题解
Vijos题解 题库地址:https://vijos.org/p P1001 谁拿了最多奖学金 题意:按照指定要求计算奖学金,直接用if判断即可 #include<iostream> us ...
- python 金币小游戏
我最近用python的pygame做了一个金币小游戏 游戏规则:移动挡板接住金币 游戏截图: 代码如下: import pygame.freetype import sys import random ...
- python循环以及控制语句
python流程 学习完本篇,你将会通过python完成以下题目 试利用break语句求解2-100之间的素数. (1)素数是指除了能被1和它本身整除外,不能被其它数所整除的数.判断一个自然数是否是素 ...
- CentOS8安装ntp实现时间同步
在CentOS8.0中默认不再支持ntp软件包,时间同步将由chrony来实现,像我这种习惯了ntp同步时间的,一时难以去适应chrony. 本文将通过wlnmp提供的源,来安装ntp服务 添加wln ...
- 在Ubuntu18.04安装docker之后,以登陆用户身份执行docker pull jenkins,报错:connect: permission denied
Using default tag: latest Got permission denied while trying to connect to the Docker daemon socket ...
- 真机连接电脑后,adb devices显示为空-解决方案
真机:小米6x,adb版本 真机连接电脑后,在cmd中输入adb devices,显示为空. 原因是真机没开启开发者选项和USB调试. 解决方案: 手机的[设置]-[我的设备]-[全部参数],多次点击 ...
- 『GoLang』控制结构
条件语句 if 是用于测试某个条件(布尔型或逻辑型)的语句,如果该条件成立,则会执行if后由大括号括起来的代码块,否则就忽略该代码块继续执行后续的代码. if condition { // do so ...
- Django整理(一) - 项目和应用创建及运行
一.项目组织结构 · 一个Project包含有多个App · 一个App就是一个Python包,就代表一个功能模块,比如: 用户模块,商品模块等 .各个功能模块间可以保持相对的独立 . ...
- 测试开发【提测平台】分享12-掌握日期组件&列表状态格式化最终实现提测管理多条件搜索展示功能
微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 本章内容思维导图如下,由于需要各种状态下的菜单操作,所以需要先实现提测信息的列表基础页面,然后再推进其他需求开发 基本知识点学习 Date ...