上一页 1 ··· 61 62 63 64 65 66 67 68 69 ··· 71 下一页
摘要: http://poj.org/problem?id=2488小错误不断 数组开的a[8][2] 我居然循环到8 还一直纠结哪错了改完后 交了一次WA 看了看讨论里面 要根据字典序 所以移动坐标差a[8][2]只能那么定义 具体看代码View Code 1 #include <stdio.h> 2 #include <string.h> 3 int n,m,x[27][27],q[27],flag; 4 char w[27]; 5 int u[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; 阅读全文
posted @ 2012-07-11 21:28 _雨 阅读(157) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016这几天做题第一次一次性AC 自信心上涨简单dfs一个大圈 中有n个小圈 填进去数 相邻圈中数的和为素数View Code 1 #include <stdio.h> 2 #include<string.h> 3 int x[21][21],v,f,y[21],c[21],n; 4 int prime(int x) 5 { 6 int i,flag = 1; 7 for(i = 2; i < x ; i++) 8 if(x%i == 0) 9 {10 ... 阅读全文
posted @ 2012-07-11 19:45 _雨 阅读(220) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2258dfs 边是双向的 节点可以走多次 开个二维数组标记边 因为可以从任一节点出发所以n次dfsView Code 1 #include <stdio.h> 2 #include<string.h> 3 int x[26][26],v,w,n; 4 void dfs(int i,int v) 5 { 6 int j; 7 for(j = 0 ; j <= n-1 ; j++) 8 { 9 if(x[i][j] == 1)10 {11 x[i][j] = 0;... 阅读全文
posted @ 2012-07-11 19:03 _雨 阅读(252) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2139BFS 借助队列 将节点的邻接点依次存入队中View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 int k[1001][1001],f[1001],n,m,p = 0,w; 5 typedef struct node 6 { 7 int num,y; 8 }st; 9 st q[1001];10 void 阅读全文
posted @ 2012-07-11 16:15 _雨 阅读(462) 评论(0) 推荐(0) 编辑
摘要: 刚开始把路径标记给取消了就一直TLEView Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 int k[1001][1001],f[1001],n,m,a,b,flag,x; 5 void dfs(int x) 6 { 7 int j; 8 f[x] = 1; 9 if(flag == 1)10 return ;11 for(j = n ;j>=1 ; j-- )12 if(k[x][j] == 1&&f[j] == 0)13 ... 阅读全文
posted @ 2012-07-11 11:24 _雨 阅读(231) 评论(0) 推荐(0) 编辑
摘要: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1882搜索 递归回溯View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<math.h> 4 int q[21][21],flag,a[21],f = 0; 5 void dfs(int i, int n) 6 { 7 int j,k,p,l,m; 8 if(f == 1) 9 return ;10 if(i>n)11 {12 . 阅读全文
posted @ 2012-07-11 10:20 _雨 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 原文地址http://princetonboy.ycool.com/post.2805302.html【摘要】本文讨论了搜索算法中“剪枝”这一常见的优化技巧.首先由回溯法解决迷宫问题展开论述,介绍了什么是剪枝;而后分析剪枝的三个原则正确、准确、高效,并分别就剪枝的两种思路:可行性剪枝及最优性剪枝,结合例题作进一步的阐述;最后对剪枝优化方法进行了一些总结.【关键字】搜索、优化、剪枝、时间复杂度引论在竞赛中,我们有时会碰到一些题目,它们既不能通过建立数学模型解决,又没有现成算法可以套用,或者非遍历所有状况才可以得出正确结果.这时,我们就必须采用搜索算法来解决问题.搜索算法按搜索的方式分有两类,一类 阅读全文
posted @ 2012-07-10 11:58 _雨 阅读(489) 评论(0) 推荐(0) 编辑
摘要: 原本因为简单的dfs就可以 写完却发现不知道如何保留一条路的路径 不能保证一条路中的节点只被走一次 导致死循环还有各种剪枝代码算是跟别人一个模子刻出来的 递归 一直走那一条路 走过就标记上 回溯的时候再取消标记View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<string.h> 4 #include<math.h> 5 int k,d,num,flag,n,m,t,a[6]; 6 char c[10][10]; 7 void dfs(int x, int y) 8 { 阅读全文
posted @ 2012-07-09 01:52 _雨 阅读(463) 评论(0) 推荐(0) 编辑
摘要: 简单并查集 有联通的就合并在一起 最后看共有多少棵树 就有多少个灾民集中区域View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 int father[201],num[201]; 4 int find(int x) 5 { 6 if(x!=father[x]) 7 { 8 father[x] = find(father[x]); 9 }10 return father[x];11 }12 void union1(int x, int y)13 {14 father[x] = y;... 阅读全文
posted @ 2012-07-08 22:07 _雨 阅读(165) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2492跟1703一样 两种状态 并查集+偏移量两只虫子发射架关系 判断有没有虫子是同性恋 两两合并 在一棵树上找右没有两个节点跟跟节点的关系(只有0,1两种)是相同的,相同就是gay注意一点 两组数据间有空行View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 int father[2001],num[2001],r[2001]; 4 int find(int x) 5 { 6 if(x!=father[x]) 7 { 8 int y = father... 阅读全文
posted @ 2012-07-08 21:45 _雨 阅读(391) 评论(2) 推荐(0) 编辑
上一页 1 ··· 61 62 63 64 65 66 67 68 69 ··· 71 下一页