poj 1077 Eight(A*)】的更多相关文章

经典的八数码问题,用来练习各种搜索=_=.这题我用的A*做的,A*的主要思想就是在广搜的时候加了一个估价函数,用来评估此状态距离最终状态的大概距离.这样就可以省下很多状态不用搜索.对于每个状态设置一个函数 h(x),这就是估价函数了(可能名词不太对请见谅),再设置一个函数 g(x), 这存的是初始状态到当前状态所用步数(或距离,视估价函数而定),再设函数 f(x) = g(x) + h(x),我们对每个状态的 f(x)的值进行排序, 然后从当前 f(x) 最小的状态继续搜索,直到搜索到最终状态或…
POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock an…
POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two pots, having the volume of A and B liters respectively. The following operations can be performed: FILL(i)        fill the pot i (1 ≤ i ≤ 2) from the ta…
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their…
POJ 1847 Tram (最短路径) Description Tram network in Zagreb consists of a number of intersections and rails connecting some of them. In every intersection there is a switch pointing to the one of the rails going out of the intersection. When the tram ent…
Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30176   Accepted: 13119   Special Judge Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15…
Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30176   Accepted: 13119   Special Judge Description The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15…
本题知识点和基本代码来自<算法竞赛 入门到进阶>(作者:罗勇军 郭卫斌) 如有问题欢迎巨巨们提出 题意:八数码问题是在一个3*3的棋盘上放置编号为1~8的方块,其中有一块为控制,与空格相邻的数字方块可以移动到空格里.我们要求指定初始棋盘和目标棋盘,计算出最少移动次数,同时要输出数码的移动数列.初始棋盘样例已给出,目标棋盘为“1 2 3 4 5 6 7 8 x”   输入: 2 3 4 1 5 x 7 6 8 输出: ullddrurdllurdruldr 详解: 八数码是经典的BFS问题,可以…
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法: (1)图的深度优先遍历和广度优先遍历. (2)最短路…
初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea…
题目大意:有一个矩形盒子,盒子里会有一些木块线段,并且这些线段是按照顺序给出的,有n条线段,把盒子分层了n+1个区域,然后有m个玩具,这m个玩具的坐标是已知的,问最后每个区域有多少个玩具 解题思路:因为线段是有序给出,所以不用排序,判断某个点在哪个区域,采用二分法,将某个点和线段的叉积来判断这个点是在线的左边或者右边,根据这个来二分找出区域 代码和思路参考与此链接:http://blog.csdn.net/wangjian8006 这也算我入门计算几何的第一道题了,首先看了一些有关资料,了解到叉…
青蛙跳跃,题意大概是:青蛙从起点到终点进行一次或多次的跳跃,多次跳跃中肯定有最大的跳跃距离.求在所有的跳跃中,最小的最大跳跃距离SF-_-(不理解?看题目吧). 可以用最小生成树完成.以起点为根,生成一棵最小生成树,直到树里包含了终点. 或者这么说吧,类似于Kruskal算法,我们每次选取不成环的最小边,直到这棵树选取了通往终点的最小边,那么最后选择的这条边必然是在树中最大的一条边,而且在其余的边中是最小的.你不会找到比这条边小的最大距离,因为比它小的最小距离都在树里了,而未选取该边前树中不包含…
https://vjudge.net/problem/POJ-1850 题意 输出某字符串在字典中的位置.字符串不合规则时输出0. 分析 首先判断字符串合法性,也就是判断是不是升序排列的.如果符合,以“vwxyz”为例,先计算长度小于5的串. 长度为1:C(26,1) 长度为2:由于规定了是升序序列,那么只要字母确定了,排列的情况也就确定了,于是此时可以认为方案数就等于从26个字母里任选两个出来,即C(26,2),经验证也是正确的. 长度为3:同上,C(26,3),长度为4:C(26,4). 接…
Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11694   Accepted: 5812   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure.…
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect togethe…
Description You have just run out of disk space and decided to delete some of your directories. Rationally, you will first have an exploration of what you have in your file system. And more rationally, you will do this exploration through a command l…
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them. Input Input consists of up to 100,000 dictionary ent…
http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以他只有通过别的石头跳过去,所以,从他的石头到Fiona的石头每一条可走的路,假设是n条,就需要你求出frog distance,这个所谓的距离就是指这n条路中,每条路选取组成这条路中最长的那边,最后一共有n条边,找这n条边里最短的那一条输出. 思路 : 就是一个最短路的问题,不过不需要求最短路的权值…
题目链接:http://poj.org/problem?id=1159 题目大意:给定一串字符,添加最少的字符,使之成为回文串. Sample Input 5 Ab3bd Sample Output 2 分析:这道题目之前有做过,就是将原字符串逆序得到另一个字符串,求它们的最长公共子序列,这样就能求得它的可以构成回文的最长字符数,用n减去即为添加最少可使之成为回文的数目. 可恨的是之前一直超内存,看了别人的解题报告,原来定义dp[MAX][MAX]时,不用int型,而是short型,内存只占in…
http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一个派上切下来的. 分析 二分答案,每次统计当前体积下能分配的人数. #include<iostream> #include<cmath> #include<cstring> #include<queue> #include<vector> #incl…
http://poj.org/problem?id=3279 题意 一个m*n的01矩阵,每次翻转(x,y),那么它上下左右以及本身就会0变1,1变0,问把矩阵变成全0的,最小需要点击多少步,并输出最小字典序的操作. 分析 爆搜铁定超时...对于一个格子,要么反转一次,要么反转零次.反转的顺序不改变最终结果.那么我们试着枚举第一行的反转情况(状态压缩),此时能影响第一行的只有第二行的格子了,依次类推,一行一行来.最后检测最后一行的值,就知道了此状态可行不可行.枚举时可以确定反转的字典序从小到大.…
Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartment in a 50-floor building several months ago. This building has only one elevator because it is a so called “rotten tail building”. There are always a…
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=1068 Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two different ways:  q By an integer sequ…
POJ 1852 Ants 题目大意 有n只蚂蚁在木棍上爬行,每只蚂蚁的速度都是每秒1单位长度,现在给你所有蚂蚁初始的位置(蚂蚁运动方向未定),蚂蚁相遇会掉头反向运动,让你求出所有蚂蚁都·掉下木棍的最短时间和最长时间. Input 输入的第一行包含一个整数,给出随后的个案数.每种情况的数据均以两个整数开头:极点的长度(以厘米为单位)和n(极点上的蚂蚁数).这两个数字后面紧跟着n个整数,给出了每个蚂蚁在杆上的位置,以从杆左端开始的距离(无特定顺序).所有输入整数均不大于1000000,并且它们之间…
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在(x1,y1),那下一秒直线移动到的整数点(x2,y2)与这个点的距离小于等于d,并且当锤子移动(x2,y2)这个点时,所有在两点的直线上的整点数都可以打到.例如(0,0)移动到(0,3).如果(0,1),(0,2)有老鼠出现就会被打到.求能够打的最多老鼠. 思路 : Dp[i][j][k]代表点(i,j)…
题意:John有n个牛棚,每个牛棚都住着一些牛,这些牛喜欢串门(drop around, 学到了...),所以John想要建几条路把他们连接起来.他选择的方法是建两个相连中转站,然后每个牛棚连接其中一个中转站就好啦.现在的问题是有一些牛相互憎恨,所以不能连同一个中转站,而又有一些牛相互喜欢,必须连同一个中转站(再次感叹,人不如牛..),现在要你来建边,要求,任意两个牛棚的距离的最大距离最短.两点距离是指哈密顿距离.比如u, v连的是同一个中转站s1,距离就是dis(u,s1)+dis(v,s1)…
生日蛋糕 Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u Submit Status Description 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体.设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当i < M时,要求Ri > Ri+1且Hi > Hi+1.由于要在蛋糕上抹奶油,为尽…
                                                               Cipher Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19502   Accepted: 5239 Description Bob and Alice started to use a brand-new encoding scheme. Surprisingly it is not a P…
Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8173   Accepted: 2149 Description A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For e…
Sumsets Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 400000/200000K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 3 Problem Description Farmer John commanded his cows to search for different sets of numbers that sum to a g…