#include <cstdlib>
#include <ctime>
#include<algorithm>
using namespace std; extern "C"
{
#include <windows.h>
#include <tchar.h>
} #define SIZE 18 LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int FindParent(int*,int);
int SepToPoint(int,POINT*,POINT*); //0代表左右关系 1代表上下关系
void BaseToRowCol(int,int*,int*);
void RowColToBase(int,int,int*); HWND hwnd;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
TCHAR szAppName[]=TEXT("first win"); MSG msg;
WNDCLASS wndclass; wndclass.style=CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=;
wndclass.cbWndExtra=;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("error"),szAppName,MB_ICONERROR);
return ;
} hwnd=CreateWindow(szAppName,
TEXT("hello"),
WS_OVERLAPPEDWINDOW^WS_MAXIMIZEBOX^WS_THICKFRAME,
, //CW_USEDEFAULT
,
, //CW_USEDEFAULT,
, //CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL); ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,,))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
} HDC hdc;
PAINTSTRUCT ps; int collect[SIZE*SIZE];
int arrSep[SIZE*(SIZE-)*];
int sepIdx=; LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
srand(time(NULL)); //初始化集合每个顶点
for(int i=;i<SIZE*SIZE;i++)
{
collect[i]=i;
}
//初始化边的数组
for(int i=;i<SIZE*(SIZE-)*;i++)
{
arrSep[i]=i;
}
//乱序边数组
random_shuffle(arrSep,arrSep+SIZE*(SIZE-)*-); //生成迷宫
while(FindParent(collect,)!=FindParent(collect,SIZE*SIZE-))
{
int sep=arrSep[sepIdx++];
POINT first,second;
SepToPoint(sep,&first,&second); int firstBase,secondBase;
RowColToBase(first.x,first.y,&firstBase);
RowColToBase(second.x,second.y,&secondBase); int pFirst=FindParent(collect,firstBase);
int pSecond=FindParent(collect,secondBase);
//合并集合
collect[pFirst]=pSecond; }
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps); { //画线
int top=,left=; //左上边距
int sep=; //间隔
//画上边
MoveToEx(hdc,left,top,NULL);
LineTo(hdc,left+SIZE*sep,top);
//画下边
MoveToEx(hdc,left,top+SIZE*sep,NULL);
LineTo(hdc,left+SIZE*sep,top+SIZE*sep);
//画左边
MoveToEx(hdc,left,top,NULL);
LineTo(hdc,left,top+SIZE*sep);
//画右边
MoveToEx(hdc,left+SIZE*sep,top,NULL);
LineTo(hdc,left+SIZE*sep,top+SIZE*sep); //画剩余的障碍边
POINT first,second;
int dir;
for(int i=sepIdx;i<SIZE*(SIZE-)*;i++)
{
dir=SepToPoint(arrSep[i],&first,&second);
if(dir==) //first的右边
{
MoveToEx(hdc,left+(first.y+)*sep,top+first.x*sep,NULL);
LineTo(hdc,left+(first.y+)*sep,top+(first.x+)*sep);
}
else //first的下边
{
MoveToEx(hdc,left+first.y*sep,top+(first.x+)*sep,NULL);
LineTo(hdc,left+(first.y+)*sep,top+(first.x+)*sep);
}
} } EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
//MessageBox(NULL,TEXT("destroy"),TEXT("caption"),MB_YESNO);
PostQuitMessage();
return ; } return DefWindowProc(hwnd,message,wParam,lParam);
} int FindParent(int* collect,int v)
{
int p=collect[v];
while(p!=v)
{
v=p;
p=collect[v];
}
return p;
} int SepToPoint(int sep,POINT* first,POINT* second) //边的坐标转换为相邻两块坐标
{
int g=sep/(SIZE*-);
int c=sep%(SIZE*-);
int dir;
if(c<SIZE-) //点是左右关系
{
first->x=g;
first->y=c; second->x=first->x;
second->y=first->y+; dir=;
}
else //点是上下关系
{
first->x=g;
first->y=c-(SIZE-); second->x=first->x+;
second->y=first->y; dir=;
}
return dir;
} void BaseToRowCol(int base,int* row,int* col)
{
*row=base/SIZE;
*col=base%SIZE;
} void RowColToBase(int row,int col,int* base)
{
*base=row*SIZE+col;
}

windows sdk版本 之 并查集生成迷宫的更多相关文章

  1. [原]windows sdk版本不对

    系统硬盘换了,重新安装一堆软件,SVN. 之前的SVN地址直接能找到 在编译vs项目的时候出现问题: windows sdk 10.0.14393.0 版本找不到 发现自己按照vs时候更新不了最新sd ...

  2. VS2017新建或拷贝项目编译时出现:找不到 Windows SDK 版本8.1.请安装所需的版本的 Windows SDK

    VS2017新建或拷贝项目编译时出现:找不到 Windows SDK 版本8.1.请安装所需的版本的 Windows SDK 或者在项目属性页的问题解决方案 解决方法: 右击项目解决方案, 选择:重定 ...

  3. 数据结构09—— 并查集(Union-Find)

    一.关于并查集 并查集(Union-Find)是一种树型的数据结构,常用于处理一些不相交集合(Disjoint Sets)的合并及查询问题.并查集(Union-Find)从名字可以看出,主要它涉及两种 ...

  4. P3402 可持久化并查集

    P3402 通过主席树维护不同版本的并查集,注意要采用按秩合并的方式,路径压缩可能会爆. 1 #include <bits/stdc++.h> 2 using namespace std; ...

  5. 算法初级面试题05——哈希函数/表、生成多个哈希函数、哈希扩容、利用哈希分流找出大文件的重复内容、设计RandomPool结构、布隆过滤器、一致性哈希、并查集、岛问题

    今天主要讨论:哈希函数.哈希表.布隆过滤器.一致性哈希.并查集的介绍和应用. 题目一 认识哈希函数和哈希表 1.输入无限大 2.输出有限的S集合 3.输入什么就输出什么 4.会发生哈希碰撞 5.会均匀 ...

  6. BZOJ 4516: [Sdoi2016]生成魔咒——后缀数组、并查集

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4516 题意 一开始串为空,每次往串后面加一个字符,求本质不同的子串的个数,可以离线.即长度为 ...

  7. BZOJ 3674 可持久化并查集加强版(路径压缩版本)

    /* bzoj 3674: 可持久化并查集加强版 http://www.lydsy.com/JudgeOnline/problem.php?id=3674 用可持久化线段树维护可持久化数组从而实现可持 ...

  8. BZOJ 3674 可持久化并查集加强版(按秩合并版本)

    /* bzoj 3674: 可持久化并查集加强版 http://www.lydsy.com/JudgeOnline/problem.php?id=3674 用可持久化线段树维护可持久化数组从而实现可持 ...

  9. ONS C++ Windows SDK 调试方法及注意事项

    此文将展示ONS C++ Windows SDK 整个调试过程,笔者直接使用sdk包中的example消息发送示例代码,开发环境为win7, 64位,Visual Studio Professiona ...

随机推荐

  1. 笔记57 Mybatis和Hibernate的比较

    一.Hibernate和MyBatis简介 1.Hibernate简介 Hibernate对数据库结构提供了较为完整的封装,Hibernate的O/R Mapping实现了POJO 和数据库表之间的映 ...

  2. 笔记33 Spring MVC的高级技术——Spring MVC配置的替代方案

    一.自定义DispatcherServlet配置  AbstractAnnotationConfigDispatcherServletInitializer所完成 的事情其实比看上去要多.在Spitt ...

  3. 关于synchronized和Lock

    原文链接:关于volatile关键字解析,synchronized和Lock参考 深入浅出,解释的非常清楚,有条理~~~ 以下为转载内容: Java并发编程:volatile关键字解析 volatil ...

  4. 网络编程之TCP协议怎么使用?

    TCP 通信的客户端:向服务器发送连接请求,给服务器发送数据,读取服务器会写的数据 表示客户端的类: java.net.Socket;此类实现客户端套接字.套接字是两台机器间通信的端点 套接字:包含了 ...

  5. Spring - @ManagedResource, @ManagedOperation, @ManagedAttribute

    总结 通过annotation (@ManagedResource, @ManagedOperation, @ManagedAttribute)注解注册MBean到JMX实现监控java运行状态 参考 ...

  6. 【RabbitMQ】六种模式与SpringBoot整合

    添加rabbitmq的依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifac ...

  7. NX二次开发-UFUN输入对象tag获得part名字UF_OBJ_ask_owning_part

    NX11+VS2013 #include <uf.h> #include <uf_modl.h> #include <uf_part.h> #include < ...

  8. cordova 与 phonegap关系

    Apache Cordova是PhoneGap贡献给Apache后的开源项目,是从PhoneGap中抽出的核心代码,是驱动PhoneGap的核心引擎.PhoneGap是一个开源的开发框架,使用HTML ...

  9. python 测试框架nose

    python测试框架nose nose不是python自带模块,这里我才用pip的方式安装 pip install nose 这样就完成了安装,然后再确认下是否安装成功了,直接打开cmd输入noset ...

  10. html清除浮动的6种方法示例

    使用display:inline-block会出现的情况: 1.使块元素在一行显示2.使内嵌支持宽高3.换行被解析了4.不设置的时候宽度由内容撑开5.在IE6,7下步支持块标签 由于inline-bl ...