随笔分类 - 搜索
摘要:Free Candies HDU - 1514
阅读全文
摘要:题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1508 Description: 有一个R行C列的网格地图,每个国家是一个四连通区域。你的任务是用红,绿,蓝,黄四种颜色给地图着色,使得相邻国家的颜色不同。一个人着色比较无趣,所以你想请
阅读全文
摘要:题面: 在纺织CAD系统开发过程中,经常会遇到纱线排列的问题。 该问题的描述是这样的:常用纱线的品种一般不会超过25种,所以分别可以用小写字母表示不同的纱线,例如:abc表示三根纱线的排列;重复可以用数字和括号表示,例如:2(abc)表示abcabc;1(a)=1a表示a;2ab表示aab;如果括号
阅读全文
摘要:下图给出了一个迷宫的平面图,其中标记为1 的为障碍,标记为0 的为可以通行的地方。010000000100001001110000迷宫的入口为左上角,出口为右下角,在迷宫中,只能从一个位置走到这个它的上、下、左、右四个方向之一。对于上面的迷宫,从入口开始,可以按DRRURRDDDR 的顺序通过迷宫,
阅读全文
摘要:DFS写法(这个简单好理解) #include<string.h> #include<iostream> #include<stdio.h> #include<algorithm> #include<queue> using namespace std; #define inf 0x3f3f3f3f
阅读全文
摘要:今天做了一些搜索的题目,感觉我又迷了,我好菜也。。 针对深搜: 为什么需要标记 记忆化搜索定义int dfs(),不需要标记,book数组只用于记录次数/步数等,一旦搜到走过的book[x][y],就直接返回,不用再往下搜索,其实就是有部分的动态规划的思想在。 一般搜索定义void dfs(),需要
阅读全文
摘要:一般搜索 注意:一般定义成void Books Exchange (easy version) CodeForces - 1249B2 The only difference between easy and hard versions is constraints. There are nn ki
阅读全文
摘要:You are given a system of pipes. It consists of two rows, each row consists of nn pipes. The top left pipe has the coordinates (1,1)(1,1) and the bott
阅读全文
摘要:Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two s
阅读全文
摘要:The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in
阅读全文
摘要:题意:求出n*n里面放置棋子的情况,使得每个棋子所在行、列、对角线没有其它棋子 思路: 直接看代码吧,代码注释比较好懂。
阅读全文
摘要:Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进制的数,并且只能由给定的M个数字构成,同时密码是一个给定十进制整数N(0<=N<=5000)的正整数倍(如果存在多个满足条件的数,那么最小的
阅读全文
摘要:一道基础广搜题 但是我全给忘完了, 重新梳理一遍 记得标记, 记得开结构体, 记得标记的数组清空啊 ##题意 给出n、a、b,表示总共1-n层楼,求出从a到b层的最少步数 有一个电梯,电梯只能上或下,接下去给出n个数,表示电梯如果到达这一层i的话可以向上或者向下走a[i]层,要是无法到达则输出-1
阅读全文
摘要:题意:在给定区域内找出一列递减的序列,输出长度即可。 思路:这一题之前写过两遍,是利用dfs进行搜索记录长度。 注意:记忆化搜索的本质是遇到已经计算过的点直接返回该值即可,不需要进行标记。但是为啥返回的时候步数不用-1我也不知道。。 先上之前dfs过的代码: 1 #include<stdio.h>
阅读全文
摘要:FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <=
阅读全文
摘要:George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the origina
阅读全文
摘要:Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two s
阅读全文
摘要:Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You m
阅读全文