06 2013 档案

摘要:用数组模拟的位运算,虽然模拟的很拙劣。。但是至少比普通搜索快1倍。 1 #include <cstdio> 2 #include <cstring> 3 #include <ctime> 4 #include <cstdlib> 5 const int SIZE = 12; 6 int sum=0,row[SIZE]={0},ld[SIZE]={0},rd[SIZE]={0}; 7 void L_m(int *a) 8 { 9 for(int i=0;i<SIZE-1;i++)10 a[i]=a[i+1];11 a[SIZE-1]=0;12 阅读全文
posted @ 2013-06-21 11:20 瓶哥 阅读(162) 评论(0) 推荐(0) 编辑
摘要:目前世界最快的N皇后算法,12皇后解25MS左右 1 #include <iostream> 2 #include <ctime> 3 using namespace std; 4 //sum用来记录皇后放置成功的不同布局数;upperlim用来标记所有列都已经放置好了皇后。 5 long sum, upperlim; 6 7 //试探算法从最右边的列开始。 8 void test(long row, long ld, long rd) 9 { 10 if (row != upperlim) 11 ... 阅读全文
posted @ 2013-06-20 15:58 瓶哥 阅读(297) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 #include 3 #include 4 #include 5 int ans,N; 6 int map[16][16]; 7 bool isCorrect(int row,int col) 8 { 9 for(int i=0;i=0&&j>=0;i--,j--)16 if(map[i][j]==1)17 return false; 18 for(int i=row+1,j=col-1;i=0;i++,j--)19 if(map[i][j]==1)20 r... 阅读全文
posted @ 2013-06-20 15:56 瓶哥 阅读(105) 评论(0) 推荐(0) 编辑
摘要:1 #include <cstdio> 2 #include <conio.h> 3 #include <windows.h> 4 typedef char ElemType; 5 6 typedef struct QNode 7 { 8 ElemType data; 9 struct QNode *next; 10 }QNode,*QueuePtr;11 12 typedef struct13 {14 QueuePtr front; //队头指针 15 QueuePtr rear; //队尾指针 16 }LinkQueue;17 18 //创建一个队... 阅读全文
posted @ 2013-06-15 23:09 瓶哥 阅读(320) 评论(0) 推荐(0) 编辑
摘要:比DFS快了4倍只用10MS就能得出结果。。 1 #include <cstdio> 2 #include <cstring> 3 #include <ctime> 4 const int XSIZE = 3; 5 const int SIZE = XSIZE * XSIZE; 6 const int MAX_C = SIZE * SIZE * 4; //最大列 7 const int MAX_R = SIZE * SIZE * SIZE; //最大行 8 const int MAX_SUDOKU = S... 阅读全文
posted @ 2013-06-14 22:50 瓶哥 阅读(298) 评论(0) 推荐(0) 编辑
摘要:50Ms左右 1 #include <cstdio> 2 #include <cstring> 3 #include <ctime> 4 #include <windows.h> 5 const int XSIZE = 4; //16*16的数独 6 const int _SIZE = XSIZE * XSIZE; 7 const int MAX_SUDOKU = _SIZE * _SIZE; //数独矩阵大小 8 const int MAX_C = _SIZE * _S... 阅读全文
posted @ 2013-06-14 20:58 瓶哥 阅读(195) 评论(0) 推荐(0) 编辑
摘要:这个模版是我从SuDoKu_DLX上面分离出来的,我也是刚接触DLX,总的来说只要能转换为精确覆盖问题的问题,都可以用DLX来解决,而且速度绝对是数一数二的。。。 1 const int SIZE = 16; 2 const int MAX_C = SIZE * SIZE * 4; //最大列 3 const int MAX_R = SIZE * SIZE * SIZE; //最大行 4 const int MAX_LINK = MAX_C * MAX_R; //链表最大范围 5 6 ... 阅读全文
posted @ 2013-06-13 22:32 瓶哥 阅读(182) 评论(0) 推荐(0) 编辑
摘要:1 #include <cstdio> 2 #include <cstdlib> 3 #include <windows.h> 4 #define MaxChild 10 5 typedef char ElemType; 6 typedef struct BiTNode 7 { 8 ElemType data; //节点的数据域 9 struct BiTNode *lchild,*rchild; //左右指针 10 }*BiTree;11 12 void visit(ElemType c,int level) //访问二叉树节点,输出... 阅读全文
posted @ 2013-06-11 23:05 瓶哥 阅读(557) 评论(0) 推荐(0) 编辑
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <windows.h> 5 #define STACK_INIT_SIZE 20 6 #define STACKINCREMENT 10 7 8 typedef char ElemType; 9 typedef struct10 {11 ElemType *top;12 ElemType *base;13 int stacksize; 14 }sqStack;15 16 //创建一个栈 17 void 阅读全文
posted @ 2013-06-10 14:26 瓶哥 阅读(200) 评论(0) 推荐(0) 编辑
摘要:1 #include <cstdio> 2 #include <conio.h> 3 #include <windows.h> 4 #define MaxSize 10 5 typedef int ElemType; //把int定义为ElemType 6 typedef struct 7 { 8 int *elem; 9 int length;10 int listsize; 11 }Sqlist;12 13 void initSqlist(Sqlist *L)14 {15 L->elem=(int*)malloc(MaxSize*sizeof(El 阅读全文
posted @ 2013-06-10 14:25 瓶哥 阅读(171) 评论(0) 推荐(0) 编辑
摘要:1 #include <cstdio> 2 #include <windows.h> 3 #define MaxSize 10 4 void insertElem(int Sqlist[],int *len,int i,int x) 5 { 6 int t; 7 if(*len==MaxSize || i<1 || i>*len+1) //检测非法插入 8 { 9 printf("This insert is illegal\n");10 return; 11 }12 for(t=*len-1;t>... 阅读全文
posted @ 2013-06-10 14:24 瓶哥 阅读(113) 评论(0) 推荐(0) 编辑
摘要:网上的Dancing Links用L[R[x]] ← L[x], R[L[x]] ← R[x]来表示节点的删除用L[R[x]] ← x, R[L[x]] ← x来表示节点的复原搞的我一头雾水,其实就是修改双向链表的左右地址,自己写一个马上有一个深刻的理解了,不过表现的形式有点不一样。 1 #include 2 #include 3 const int MAX=10; 4 typedef struct node 5 { 6 int num; 7 struct node *left,*right; 8 }point; 9 point *head=(point*)malloc(... 阅读全文
posted @ 2013-06-08 23:55 瓶哥 阅读(153) 评论(0) 推荐(0) 编辑
摘要:昨天刚接触BFS算法,用的queue队列,算法的理解应该没什么问题,但是BFS和DFS在输出最短的路径上有点不一样,BFS如果要输出路径就必须要做记录,然后在逆向DFS,我用的是逆向链表记录路径,队列弹出推入的都是结构体地址。 1 /* 2 Name: 老鼠走迷宫(二) BFS 3 Copyright: 4 Author: 顾骏 5 Date: 23/05/13 22:14 6 Description: BFS 7 */ 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <queue> 11 ... 阅读全文
posted @ 2013-06-06 12:17 瓶哥 阅读(511) 评论(0) 推荐(0) 编辑
摘要:40Ms 1 #include <stdio.h> 2 #include <string.h> 3 #include <time.h> 4 int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}}; 5 int num[9][9]; 6 void Dfs(int,int); 7 bool Check(); //检测数独数组是否满足要求 8 bool Check_(int,int,int); //检测一行&一列&3*3小格子是否有相同的数 9 10 void input(void) 11 { 12 char str[1 阅读全文
posted @ 2013-06-04 21:59 瓶哥 阅读(143) 评论(0) 推荐(0) 编辑
摘要:[转自:http://blog.csdn.net/hss871838309/article/details/7376381#]这个非原创、、、、、但是,为了让更多人看到,无奈的原创一下、、、写的很好,虽然真正学习算法(说的好听是学算法,不好听就是A题)近一年了,但是,学习的效率非常低,最近才稍稍掌握点技巧。这篇文章不知道是哪位大牛写的,在朋友的博客中看到了,觉得很有借鉴作用,就粘了过来,共勉。。。。加油!!!吖飒~~~~刻苦的训练我打算最后稍微提一下。主要说后者:什么是有效地训练?我想说下我的理解。很多ACMer入门的时候,都被告知:要多做题,做个500多道就变牛了。其实,这既不是充分条件、也 阅读全文
posted @ 2013-06-03 17:23 瓶哥 阅读(137) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示