456
2016-07-30 09:00
253 查看
#include <stdio.h>
#include <math.h>
#define MaxLength 100 //�������ȶ��У�Open��������
#define Height 15 //��ͼ�߶�
#define Width 20 //��ͼ���
#define Reachable 0 //���Ե���Ľ��
#define Bar 1 //�ϰ���
#define Pass 2 //��Ҫ�ߵIJ���
#define Source 3 //���
#define Destination 4 //�յ�
#define Sequential 0 //˳�����
#define NoSolution 2 //����
#define Infinity 0xfffffff
#define East (1 << 0)
#define South_East (1 << 1)
#define South (1 << 2)
#define South_West (1 << 3)
#define West (1 << 4)
#define North_West (1 << 5)
#define North (1 << 6)
#define North_East (1 << 7)
typedef struct
{
signed char x, y;
} Point;
const Point dir[8] =
{
{0, 1}, // East
{1, 1}, // South_East
{1, 0}, // South
{1, -1}, // South_West
{0, -1}, // West
{-1, -1}, // North_West
{-1, 0}, // North
{-1, 1} // North_East
};
unsigned char within(int x, int y)
{
return (x >= 0 && y >= 0
&& x < Height && y < Width);
}
typedef struct
{
int x, y;
unsigned char reachable, sur, value;
} MapNode;
typedef struct Close
{
MapNode *cur;
char vis;
struct Close *from;
float F, G;
int H;
} Close;
typedef struct //���ȶ��У�Open��
{
int length; //��ǰ���еij���
Close* Array[MaxLength]; //��۽���ָ��
} Open;
static MapNode graph[Height][Width];
static int srcX, srcY, dstX, dstY; //��ʼ�㡢�յ�
static Close close[Height][Width];
// ���ȶ��л����
void initOpen(Open *q) //���ȶ��г�ʼ��
{
q->length = 0; // ����Ԫ�����ʼΪ0
}
void push(Open *q, Close cls[Height][Width], int x, int y, float g)
{ //�����ȶ��У�Open�������Ԫ��
Close *t;
int i, mintag;
cls[x][y].G = g; //����ӽڵ�����
cls[x][y].F = cls[x][y].G + cls[x][y].H;
q->Array[q->length++] = &(cls[x][y]);
mintag = q->length - 1;
for (i = 0; i < q->length - 1; i++)
{
if (q->Array[i]->F < q->Array[mintag]->F)
{
mintag = i;
}
}
t = q->Array[q->length - 1];
q->Array[q->length - 1] = q->Array[mintag];
q->Array[mintag] = t; //����ۺ���ֵ��С�ڵ����ڶ�ͷ
}
Close* shift(Open *q)
{
return q->Array[--q->length];
}
// ��ͼ��ʼ������
void initClose(Close cls[Height][Width], int sx, int sy, int dx, int dy)
{ // ��ͼClose���ʼ������
int i, j;
for (i = 0; i < Height; i++)
{
for (j = 0; j < Width; j++)
{
cls[i][j].cur = &graph[i][j]; // Close����ָ�ڵ�
cls[i][j].vis = !graph[i][j].reachable; // �Ƿ
#include <math.h>
#define MaxLength 100 //�������ȶ��У�Open��������
#define Height 15 //��ͼ�߶�
#define Width 20 //��ͼ���
#define Reachable 0 //���Ե���Ľ��
#define Bar 1 //�ϰ���
#define Pass 2 //��Ҫ�ߵIJ���
#define Source 3 //���
#define Destination 4 //�յ�
#define Sequential 0 //˳�����
#define NoSolution 2 //����
#define Infinity 0xfffffff
#define East (1 << 0)
#define South_East (1 << 1)
#define South (1 << 2)
#define South_West (1 << 3)
#define West (1 << 4)
#define North_West (1 << 5)
#define North (1 << 6)
#define North_East (1 << 7)
typedef struct
{
signed char x, y;
} Point;
const Point dir[8] =
{
{0, 1}, // East
{1, 1}, // South_East
{1, 0}, // South
{1, -1}, // South_West
{0, -1}, // West
{-1, -1}, // North_West
{-1, 0}, // North
{-1, 1} // North_East
};
unsigned char within(int x, int y)
{
return (x >= 0 && y >= 0
&& x < Height && y < Width);
}
typedef struct
{
int x, y;
unsigned char reachable, sur, value;
} MapNode;
typedef struct Close
{
MapNode *cur;
char vis;
struct Close *from;
float F, G;
int H;
} Close;
typedef struct //���ȶ��У�Open��
{
int length; //��ǰ���еij���
Close* Array[MaxLength]; //��۽���ָ��
} Open;
static MapNode graph[Height][Width];
static int srcX, srcY, dstX, dstY; //��ʼ�㡢�յ�
static Close close[Height][Width];
// ���ȶ��л����
void initOpen(Open *q) //���ȶ��г�ʼ��
{
q->length = 0; // ����Ԫ�����ʼΪ0
}
void push(Open *q, Close cls[Height][Width], int x, int y, float g)
{ //�����ȶ��У�Open�������Ԫ��
Close *t;
int i, mintag;
cls[x][y].G = g; //����ӽڵ�����
cls[x][y].F = cls[x][y].G + cls[x][y].H;
q->Array[q->length++] = &(cls[x][y]);
mintag = q->length - 1;
for (i = 0; i < q->length - 1; i++)
{
if (q->Array[i]->F < q->Array[mintag]->F)
{
mintag = i;
}
}
t = q->Array[q->length - 1];
q->Array[q->length - 1] = q->Array[mintag];
q->Array[mintag] = t; //����ۺ���ֵ��С�ڵ����ڶ�ͷ
}
Close* shift(Open *q)
{
return q->Array[--q->length];
}
// ��ͼ��ʼ������
void initClose(Close cls[Height][Width], int sx, int sy, int dx, int dy)
{ // ��ͼClose���ʼ������
int i, j;
for (i = 0; i < Height; i++)
{
for (j = 0; j < Width; j++)
{
cls[i][j].cur = &graph[i][j]; // Close����ָ�ڵ�
cls[i][j].vis = !graph[i][j].reachable; // �Ƿ
相关文章推荐
- (转)项目管理知识体系术语 456
- NYOJ 456 邮票分你一半
- #小练习 SGMLParser练习 分类: HTMLParser 2013-11-12 15:50 456人阅读 评论(0) 收藏
- NYOJ 456 邮票分你一半
- nyoj456邮票分你一半
- 倒序输出(如输入456则输出654)
- NYOJ 456 邮票分你一半 【0 1背包】
- js如何将数字表示成23,456,987
- nyoj456_邮票分我一半
- nyoj 456 邮票分你一半
- Codeforces Round #456 Div.2 B. New Year's Eve
- :流行木马(456).INI,无法彻底清除
- NYOJ 456 邮票分你一半
- 456
- [它山之石] 一件事情,如果你不能说清楚,十有八九你就做不好 分类: 项目管理 2014-07-02 14:17 456人阅读 评论(0) 收藏
- nyoj-456 邮票分你一半
- 输入以逗号分隔的整数,如123,234,345,456,111等,并以回车结束输入
- 网络请求456
- NYOJ325、NYOJ456
- leetcode-456-Convert a Number to Hexadecimal