
搜索
iDev9
iOS Developer
展开
-
poj1915 Knight Moves
题目: http://poj.grids.cn/problem/1915/代码: #includeusing namespace std;int n,l;int a,b,c,d;int move[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};int visited[3原创 2010-05-02 23:04:00 · 327 阅读 · 0 评论 -
hdu1175 连连看
题目:hdu1175方法:bfs思想:本题主要是看两个棋子能否消去(可以通过一条线连起来,这条线不能经过其它棋子,而且线的转折次数不超过两次),可以用bfs进行搜索,得到从源点到终点的最短路径,在这个过程中可以加一个记录转动次数的数组,对于那些被扩展的点,如果它的转向次数小于等于原创 2011-07-18 17:34:30 · 670 阅读 · 0 评论 -
hdu1241 OilDeposits
题目:hdu1241 zjut1012 tzc1334方法:dfs思想:本题主要是求有几块油田,中文题目可查看zjut1012,可以利用dfs,从每一个可以移动的点出发,可以走到的就作一个标记,进行了几次搜索,答案就是几次,本题不需要回溯。代码://zjut1012 tzc原创 2011-07-26 08:55:21 · 604 阅读 · 0 评论 -
buct1766 Following Orders
题目:buct1766方法:dfs思想:利用搜索或next_permutation产生下一个排列,然后判断该排列是否满足要求,如果满足要求输出即可。代码:#include #include #include using namespace std; char var[50]原创 2011-07-23 21:24:23 · 533 阅读 · 0 评论 -
tzc2731 存钱计划(二)
题目:tzc2731方法:bfs代码:#include #include using namespace std; struct node { int n,num; }; int n,m; bool g[1005][1005],visited[1005]; int s,e原创 2011-07-23 19:34:40 · 711 阅读 · 0 评论 -
buct1711 错位排序
题目:buct1711方法:dfs思想:用dfs找出所有可能的排列,并判读该排列是否是错位排序序列,若是就直接输出便可。代码:(1)#include using namespace std; int n,a[10],visited[10]; void dfs(int t)原创 2011-07-22 20:00:49 · 516 阅读 · 0 评论 -
fzu1684 迷宫救美
<br />题目链接:fzu1684<br /> <br />代码:<br /> <br />#include <iostream> #include <cmath> #include <queue> using namespace std; struct node { int x,y,step; }tmp,head; queue <node> q; char map[25][25]; int e[25][25]; int dir[4][2]={-1,0,0,-1,1,0,0,1}; i原创 2010-09-24 08:32:00 · 741 阅读 · 1 评论 -
pku2676Sudoku
题目链接:pku2676 解决数独问题代码:dfs、回溯#include using namespace std; char map[10][10]; int visited[10][10],flag; bool judge(int i,int j,int u) { for(int a=1;a原创 2010-08-26 12:00:00 · 548 阅读 · 0 评论 -
fzu1408位图
题目链接:fzu1408 hnu10109代码:bfs //1 #include using namespace std; int map[190][190]; int n,m; int move[4][2]={-1,0,0,-1,1,0,0,1}; struct node { int x,y,step;}tmp,front; queue list; void bfs() { while(!list.empty()) { front=list.front();原创 2010-08-25 20:07:00 · 495 阅读 · 0 评论 -
pku1915Knight Moves
<br />题目链接:pku1915<br /> <br />代码:bfs<br /> <br />#include<iostream><br />#include <string><br />#include <queue><br />using namespace std;<br />int n,s;<br />int a,b,c,d,l;<br />bool visited[300][300];<br />int dir[8][2]={1,2,2,1,-1,-2,-2,-1,-1,2,2,-1,1,-原创 2010-08-24 17:18:00 · 405 阅读 · 0 评论 -
pku2531Network Saboteur
<br />题目链接:pku2531<br /> <br />代码一: dfs<br /> <br />#include <iostream> #include <algorithm> #include <vector> using namespace std; vector <int> v1,v2; int n,ans,a[22][22]; void sum() { int temp=0; for(int i=0;i<v1.size();i++) for(int j=0;j<原创 2010-08-24 13:02:00 · 389 阅读 · 0 评论 -
pku3256CowPicnic
<br />题目链接: pku3256<br /> <br />思路:找出每头牛能够走的地方,最后看是否走过的牛的数目等于牛的数目的有几个地方。<br /> <br />代码:dfs<br /> <br />// 1 ≤ K ≤ 100 1 ≤ N ≤ 1,000 1 ≤ M ≤ 10,000 #include <iostream> using namespace std; int k,n,m; bool map[1005][1005],visited[105][1005]; int loc[1原创 2010-08-24 13:41:00 · 368 阅读 · 0 评论 -
hdu1253胜利大逃亡
<br />题目链接:hdu1253<br /> <br />代码:bfs<br /> <br />模板:<br /> //使用STL中的队列 void BFS( ) { 首结点入队列Q; while ( ! Q.empty() ) //队列不空 { temp=Q.front(); if ( 到达目的状态 ) { 输出结果; break; } Q.pop( );原创 2010-08-24 12:14:00 · 931 阅读 · 0 评论 -
pku2907Collecting Beepers
<br /> 题目链接:pku2907<br /> <br />代码一:用next_permutation函数<br /> <br />//next_permutation函数的使用 #include <iostream> #include <stdlib.h> #include <algorithm> using namespace std; int main(int argc, char *argv[]) { int casenum; int x0,y0,num; int n,原创 2010-08-23 14:43:00 · 339 阅读 · 0 评论 -
hdu1078FatMouse and Cheese
<br /> 题目链接:hdu1078<br /> <br />代码:dfs<br /> <br />// each time he can run at most k locations to get into the hole before being caught by Top Killer. //Given n, k, and the number of blocks of cheese at each grid location, //compute the maximum amount原创 2010-08-19 11:36:00 · 406 阅读 · 0 评论 -
pku1899Farmer Bill's Problem
题目:pku1899代码:该代码参考何长兵的博客//1 using namespace std; struct point { int x,y; }; struct circle { int x,y,r; }; struct rectangle { point ld,rp; }; circle c[105]; rectangle r[105]; int n,used[105]; // 判断两个矩形是否相交 bool rectangle_cross(rectangl原创 2010-08-04 20:21:00 · 482 阅读 · 0 评论 -
hdu1010 Tempter of the Bone
题目:hdu1010 tzc1221 方法:dfs 思想:由于本题中规定只有在固定时刻到达目的点才能逃脱, 不能提早,更不能延迟,故不能用bfs。可以用dfs找出所有情况, 若有可行解,直接返回即可。本题比较郁闷的是,在tzc上将方向 数组int dir[4][2]稍微变动两下,就会超时。这也是今后出现TLE时 该考虑的重要的一点吧,可以作为经验教训。 代码: #incl原创 2011-07-26 10:40:13 · 1443 阅读 · 5 评论