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
;
int y;
int Step;
}state; The //status indicates that the first Cup has an X-liter of water, the Second Cup has an ascending water, and step indicates the number of steps required to the current state
State que[max],p,q; //que for Queues
int f,r;
int N,a,b,c,x,y,z,d,newx,newy;
int Vis[max][max]; //tag array records whether a state has been included
void push () {
QUE[R].X=NEWX;
Que[r].y=newy;
que[r++].step=q.step+1;
Vis[newx][newy]=1;
}
int
him final, because there can only be one person in one grid. you can assume the PS must stand on '. '. so, it also costs you 1 mV to enter this grid.
Inputthe first line of the inputs is T, which stands for the number of test cases you need to solve.
Then T cases follow:
Each test case starts with a line contains three numbers n, m and MV (2 Outputoutput the N * m map, using '*'s to replace all the grids 'y' can arrive (cannot the 'y' grid itself). Output a blank line after each case.
Sample In
HDU 5040 BFS + pressure, hdu5040bfs
2014 ACM/ICPC Asia Regional Beijing Online
For N * N Matrices
M start point, T end point
Cameras with starting directions north N, East E, South S, and West W can be detected in the range of self-directed 1 grid and Rotate 90 ° clockwise every 1 second.
If there is a lamp in front or a place on your own, it takes 3 seconds to move it, or wait for a second to move it.
BFS
~
[Cpp]# Include # Include # Include Using namespace std;Const int inf = ~ 0u> 2;Const int maxn = 50010;Int n, m;Struct Edge {Int v, w, next;} Edge [2 * maxn];Int head [maxn], E, num [maxn];Void add_edge (int a, int B, int w){Edge [E]. v = B;Edge [E]. w = w;Edge [E]. next = head [a];Head [a] = E ++;}Int dis1 [maxn], dis2 [maxn];Bool vis [maxn];Int q [maxn];Void bfs (int s, int ss, int dist []) {Fill (dist, dist + n + 1, inf );Fill (vis, vis + n + 1,
I will introduce the basic storage methods, DFS and BFS, undirected graphs, Minimum Spanning Tree, shortest path, and active network (AOV and AOE) in detail.C ++Graph application. In the previous article, we introduced the basic storage methods.DFSAndBFS.
DFS and BFS
For non-linear structures, traversal will first become a problem. Like binary tree traversal, a graph also has two types: Deep preference sear
When to use DFS, when to use BFS?The title of the two-dimensional array, n less than 20, applies to DFS. and generally nBasic steps of BFS1. Add an initial point (one or more) to the end of a collection2. Remove the point from the head of the assembly, determine the perimeter of the initial point, and join the qualifying points to the queue3. Repeat the 2 operation until the collection is empty. (typically each point is queued only once)In general, th
G.adjacentedges (v) Do4 ifVertex W isn't labeled as discovered then5Recursively call DFS (G,W)The DFS pseudo-code for non-recursive notation is as follows:Input G v of G1Procedure Dfs-iterative (G,V):2Let S be a stack3S.push (v)4 whileS is not empty5V←s.pop ()6ifV is not labeled as discovered:7Label V as discovered8 forAll edges from V to W in G.adjacentedges (v) Do9S.push (W)BFS (Breadth-first Search)This is the relative to the
The message about BFS was first seen on magazine in Linux. Shortly afterwards, gg1 Android mobile Rom was changed to CM and began to use BFS as the scheduler of kernel in his beta version cyanogenmod, after the trial, we found that the speed of the mobile phone system was significantly faster. Sliding the screen on the left and right by hand is as smooth as rolling pages under opera, resulting in a lot of f
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.