problem DescriptionPass a year learning in Hangzhou, Yifenfei arrival hometown Ningbo at finally. Leave Ningbo One year, Yifenfei has many people to meet. Especially a good friend Merceki.Yifenfei's home is on the countryside, but Merceki's home is in the center of the city. So Yifenfei made arrangements and Merceki to meet at a KFC. There is many KFC in Ningbo, they want to choose one and the total time to it is most smallest.Now give your a Ningbo map, Both Yifenfei and Merceki can move up, do
http://acm.hdu.edu.cn/showproblem.php?pid=3567Compared to eight, it seems that the target State has been changed from certain to indeterminate, but Cantor expansion + Manhattan for H value of a * and ida* are not, but also difficult to control the dictionary orderIn other words, although there are many starting states, but which one is 1, which one is 2 is not the most important, the most important is the corresponding to the target State, so you can re-encode the starting state to "12345678" th
4 Values whose Sum is 0
Time Limit: 15000MS
Memory Limit: 228000K
Total submissions: 20020
accepted: 5977
Case Time Limit: 5000MS
Description The SUM problem can be formulated as Follows:given four lists A, B, C, D of an integer values, compute how many Quadruplet (A, B, C, D) ∈a x B x C x D are such that A + B + c + d = 0. In the following, we assume so all lists have the same size n.
Input the the ' the ' input file contains the
the shortest path to the maze
Given a maze of size n*m. The maze is made up of channels and walls, each of which moves to the adjacent upper and lower left and right four-grid channels. Requests the minimum number of steps required from the start point to the end point. If you cannot reach it, the output "cannot go there". (n,m
Input sample: N=5,m=5
#S # # # #
. ##.
#.###
.. ###
Output: 5
Analysis: This is a BFS template problem, direct demand for
Daily Punch-In (1/2)
Portal: Click to open link
Main topic:
Look for an integer that is a multiple of n (1
Ideas:
First, n is a number not less than 1, assuming the final number is m, then M is necessarily the first bit is 1.
After determining the first, there are two cases: 11 and 10, this time with a bfs/dfs can be solved, for the sake of insurance write BFS. In each case use m%n, if the result is
Topic links
Test instructions: Your task is to help J out of a maze of fires spreading. J can move up or down in four directions per minute, and all the burning squares will spread around. There are some obstacles in the maze, J and fire can not enter. When J went to the boundary lattice of a maze, we thought he had gone out of the maze.
Idea: This is a problem above the white, in fact, as long as each lattice what time on fire to deal with it. Two times B
It's a lot more fire than the general BFS.
So, first, make a fire. BFS pre-processing each lattice ignition time
Lazy to open the number of groups and then wrong for half a day
#include
Test Instructions:N (1e3), K (1e6), A1~ak (1E3). Select the minimum number of AI (can be repeated) T, so that sum (AI)/t/1000==n/1000 set up.
The following:K (1e6), A1~ak (1E3)--and the number is only 1e3.
SUM (AI)/t/1000==n/1000--sum (AI) ==t*n---sum (ai-n) ==0
t
Solution One: BFS
If there is a set of solutions b1+b2+...+bt==0, then we can change the position of the array elements so that all prefixes and ranges are [ -1000,1000].
Then we can use 0
Topic Connection: http://poj.org/problem?id=3126
Test instructions: Given two prime numbers, find the shortest prime number path between the two.
This problem with a single bfs is enough, but, or practice the double BFS.
Code:
#include
Title Link: http://uva.onlinejudge.org/external/116/11624.pdf
Test instructions: Given a maze and some ignition points, the fire will constantly want to spread around, seeking a shortest path to escape the maze.
Idea: First use BFS to find out the fire spread to each point of the shortest time, you can set the # time to 0, '. ' The fire can't be set to OO (it should be noted here, WA once). The following is the conventional
.
The real vertices count is *
Searchgraph.java
Import java.util.ArrayList;
Import Java.util.Iterator;
Import java.util.LinkedList;
Import java.util.List;
Import Java.util.Queue;
Import Java.util.Stack; public class Searchgraph {public static list
Main.java
Import java.util.List;
public class Main {public
static Graph createtestgraph () {
graph G = new Graph ();
G.addvertex ("A");
G.addvertex ("B");
G.addvertex ("C");
G.addvertex ("D");
G.addvertex ("E");
G.addv
Algorithm idea: BFs.
This is a short-circuited question using BFs. For the entire code framework, refer to "Liu rujia's algorithm competition", including the BFS () function and print_path () function.
Key points:
1. because there is a monster with HP as N, if you press the queue directly according to the conventional method, it will not be the "shortest circuit"
Test instructions: Give a graph of n points, m edges, each edge has a color, the shortest path from node 1 to node n color dictionary order.Analysis: First of all this is a shortest path problem, it should be BFS, because to ensure that the shortest path, but also to consider the dictionary sequence, feel very troublesome, and not good to do, the fact with two times BFS,The first is the reverse
as the reverse thinking, or can be solved with breadth-first search. Without considering how to reach the final state with the minimum number of steps from the input state, the final state of all the results is (01234567), then, in turn, only ask for the minimum number of steps to reach all the results in the final state and record it, then check the table. 0 represents an empty position, the grid around the empty position is moved to 0 in a breadth-first way, and the result of the minimum numb
The main idea: a n*m in the picture, "." can go, "X" Cannot go, "*" for starting point, ask from beginning to start around all X lap back to start at least how many steps to take.Beginning to see this problem, their own brain hole how to write, should be able to, and then ran to see the puzzle, and learned a new posture ...is a sample, red handwriting is the way, need to walk 13 steps. This is obviously the BFS problem, the question is how to let
program that does the counting for me. then I'll be able to just start both these programs before I go to bed, and I'll sleep tight until the morning without any disturbances. I need you to write this program for me.
InputThe first line of input contains a single number T, the number of test cases to follow.
Each test case begins with a line containing two numbers, H and W, the height and width of the sheep grid. then follows H lines, each containing W characters (either # or .), describing tha
[Cpp] // question: the diameter of the tree // thought: // the diameter of the tree refers to the longest simple path of the tree. Method: Twice BFS: first select a starting point BFS to find the longest path end point, and then perform BFS from the end point, then the longest path found by BFS is the diameter of the t
PackageMyalgorithm;Importjava.util.Arrays;Importjava.util.LinkedList;ImportJava.util.Queue;/*The structure of the location and value of the BFS used for recording*/classnode{Node (intXparamintYparam,intValparam) { This. x =Xparam; This. y =Yparam; This. Value =Valparam; } intX,y,value;} Public classShortPath {/*Global Shortest Path*/ Public intStepnum = 999; /*build the maze of 11*11, Hero H in the location of (the), to save beauty m
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.