acm_搜索
文章平均质量分 63
小七和小墨
http://blog.csdn.net/ccsu_cherish
http://blog.csdn.net/shahdza/article/details/6632538
展开
-
hdu 1045 Fire Net dfs
http://acm.hdu.edu.cn/showproblem.php?pid=1045深搜。在find()函数找上下左右是否有碉堡的时候,要从x-1和y-1为起点开始搜。如果从0为起点开始搜 则错误。#include#include#include#include#include#include#includeusing namespace std;int n,tmp原创 2013-07-13 16:03:42 · 628 阅读 · 0 评论 -
hdu1242 Rescue 优先队列BFS
Angel's friends want to save Angel. Their task is: approach Angel. We assume that "approach Angel" is to get to the position where Angel stays. When there's a guard in the grid, we must kill him (or h原创 2013-12-28 16:21:15 · 535 阅读 · 0 评论 -
codeforces 369C Valera and Elections DFS
The city Valera lives in is going to hold elections to the city Parliament.The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to a原创 2013-11-30 17:07:32 · 717 阅读 · 0 评论 -
poj3009 Curling 2.0 DFS搜索
On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is ma原创 2013-09-05 21:28:02 · 483 阅读 · 0 评论 -
poj2386 Lake Counting DFS
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water原创 2013-09-03 15:47:22 · 510 阅读 · 0 评论 -
poj1852 Ants 穷竭搜索
An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they t原创 2013-09-02 18:00:06 · 632 阅读 · 0 评论 -
nyist 吝啬的国度 dfs
数据太多用vector。#include#include#include#include#include#include#include#includeusing namespace std;#define Min(a,b) (a)<(b)? a:bint pre[100005];int n,s,t;vectorv[100005];void dfs(int beg)原创 2013-08-15 16:43:20 · 464 阅读 · 0 评论 -
bnu1023 水淹七军 dfs/bfs
这个题目两中搜索都ok。不用搜索都可以- -。如果有放水点的高度大于等于司令部的高度,那么就被淹了。。dfs:#include#include#include#include#include#include#includeusing namespace std;int f[4][2]={0,1,1,0,0,-1,-1,0};int n,m,sx,sy;int a[201原创 2013-08-03 19:17:19 · 920 阅读 · 0 评论 -
hdu 1312 red and black BFS
熟悉一下BFS的写法。#include#include#include#include#include#include#includeusing namespace std;int f[4][2]={0,1,1,0,0,-1,-1,0};int n,m,tmp;char a[21][21];struct node{ int x,y;};node e,v,s;原创 2013-07-24 11:12:08 · 587 阅读 · 0 评论 -
hdu2616Kill the monster 深搜
题目大意是一个人要杀死一个怪物,怪物的血量HP。有n种方式,每种对怪物的伤害值不同。而且当怪物的HP小于等于某一值时,会造成double伤害。搜索分两次,每次先对当前伤害做一次,然后dfs下一次伤害。感觉还是没有体会到dfs的核心。如何建立搜索的过程太模糊了#include#include#include#include#include#include#includeusin原创 2013-07-23 15:38:57 · 644 阅读 · 0 评论 -
hdu 1016Prime Ring Problem
同样是dfs。判断相邻是否是素数,用dfs因为数据不大,可以直接将40以内的素数直接写出来,判断的时候就方便很多。#include#include#include#include#include#include#includeusing namespace std;int a[21],n,pre;int b[21],c[21];int f[40]={0,0,1,1,0,原创 2013-07-22 17:10:08 · 526 阅读 · 0 评论 -
hdu1426 Sudoku Killer dfs
一个填数独的游戏,注意横,纵,方格块都检索一遍就好了。计算方格块的坐标:r = x%3==0? x-2:x-x%3+1;c = y%3==0? y-2:y-y%3+1;#include#include#include#include#include#include#includeusing namespace std;int a[10][10];boo原创 2013-07-21 19:20:54 · 570 阅读 · 0 评论 -
hdu1010Tempter of the Bone dfs+奇偶剪枝
题目大意是某人陷入了一个迷宫,他要逃出去,‘x’是墙走不通。‘.’是可走点。‘s’是起始点,‘d’是终点。走一步一秒,在限定时间内走完就输出“YES”关键处就是要进行奇偶剪枝。tmp=(t-abs(sx-ex)+abs(sy-ey))%2; 为奇数就是代表走不通。#include#include#include#include#include#incl原创 2013-07-21 10:41:34 · 628 阅读 · 0 评论 -
hdu2611 Sequence two 深搜
此题和2610差不多。只是要求输出的子序列要从小到大排列。如1 3 2的子序列要写成 {1},{2},{3},{1,2},{1,3}。这就要求在输入数据的时候用结构体保存数据和当前数据的位置。在进行深度搜索的时候要先对数据进行排序,如果数据相同。就将位置小到大排序。对于1 3 2 ,排序后是1 2 3,子序列{2,3}是不能出现的,因为2的位置比3大 原数列是不会构成这样的子序列的。这两题原创 2013-07-20 10:45:02 · 709 阅读 · 0 评论 -
hdu 2610Sequence one 深度搜索
题意很简单就是在给定的序列中找到固定个数的递增的子序列,如果子序列的总个数少于要求的个数,那么就把所有的子序列输出即可,注意每组测试用例就为有一空行。要注意要挑出重复的子序列。#include#include#include#include#include#includeusing namespace std;//len:搜索的长度,tmp:记录有多少个串了int a[10原创 2013-07-19 11:49:36 · 626 阅读 · 0 评论 -
hdu 1312 Red and Black dfs
简单dfs#include#include#include#include#include#includeusing namespace std;int f[4][2]={0,1,1,0,0,-1,-1,0};char a[21][21];int tmp,n,m;void dfs(int x,int y){ int x1, y1; for(int i=0;原创 2013-07-15 11:42:08 · 636 阅读 · 0 评论 -
zju 1008 Gnome Tetravex dfs
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008check() 如果在k不是在最左边就水平两个三角形比较。不是在最上边就垂直两个三角形比较。#include#include#include#include#include#includeusing namespace std;int a[30][原创 2013-07-14 13:51:05 · 588 阅读 · 0 评论 -
hdu2899 Strange fuction 三分搜索
Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 Can you find the minimum value when x is between 0 and 100.题解:函数是凸性的,用二分搜索需要做特殊处理,求解凸性函数用三分搜索是比较方便的。类似二分的定义Left和Right,mid =原创 2013-12-27 20:49:24 · 542 阅读 · 0 评论