Link:http://poj.org/problem?id=3278
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 62113
Accepted: 19441
DescriptionFarmer John had been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point n (0≤ N ≤100,000) on a number line and the cow are at a point K (0≤ K ≤100,000) on the same number line. Farmer John has modes of transportat

question. The question was directly made using brute force and I had been wondering if it would be enough for Division 2, then at the beginning I also want to use violence to do, but some of the later do not take into account, this question is also more than the copy of the http://blog.csdn.net/whjkm/article/details/26985421 of the problem (once that the link ), later, I carefully read the question. There is a big difference between the question and the question. The simple question is that it

Poj 3278 Catch That Cow (broad search), poj3278
Catch That Cow
Time Limit:2000 MS
Memory Limit:65536 K
Total Submissions:45087
Accepted:14116
DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on t

search question. At the beginning, I thought it was necessary to find a Unified Algorithm formula to calculate the minimum number of steps from "Start number" to "end number, however, after thinking about it for half a day, I finally thought about solving the problem with violence. But isn't this an algorithm question for BFS? Yes, it is not a common Linear brute force search, but the BFS concept is needed. After careful analysis, you can know that computer programs cannot dynamically decide ho

=Q.front (); at Q.pop (); - if(q2 = = b) {//the output went a few steps after I found it. -printf"%d\n", STEP[Q2]); - return ; - } - //John, go--1 only if he has a positive coordinate at this point . in intx = Q2-1; - if(!maps[x] Q2 >0) { toMAPS[X] =true; +Q1 =x; -STEP[Q1] = step[q2] +1; the Q.push (Q1); * } $ //as John walked backwards only-1 so only Q2 Panax Notoginseng if(Q2 b) { -x = q2 +1; the if(!Maps[x])

Title Link: http://poj.org/problem?id=3278Test instructions: one-dimensional space. Initial coordinate n. Goal K. Move the way n-1,n+1,2*n, and then want to know the minimum number of steps to the end,Idea: The BFS can no longer water. At first I don't want to knock. Knock on the happy re. Then know the existence of "pruning". is to optimize it. If the current location is now>k. That's the only way now-1 can go. Well. If you do not prune, re data such as 0 100000.The focus is on pruning.The AC c

Source: http://poj.org/problem? Id = 3278
Question: How many steps are required from the start point to the end point for a start point and an end point. You can take one step to the left, one step to the right, or the coordinate is multiplied by 2.
Idea: a raw BFs, a water question.
Code:
# include
# include
# include
# include
using namespace STD; # define CLR (ARR, Val) memset (ARR, Val, sizeof

/*POJ 3278 Catch that Cow---simple BFS*/#include#include#includeusing namespacestd;Const intMAXN =100005;BOOLVISIT[MAXN];intSTEP[MAXN];intBFsintNintk) { if(n = =k)return 0; memset (Visit,0,sizeofvisit); Queueint> q;//on the node where the store is visited but the next point is to be judgedQ.push (n); Step[n]=0; Visit[n]=1; intX,next; while(!Q.empty ()) {x=Q.front (); Q.pop (); for(inti =0; I 3; ++i) { //i = 0,1,2 means wide search in d

Catch that cowtime limit: 2000 msmemory limit: 65536 kbthis problem will be judged on PKU. Original ID: 3278
64-bit integer Io format: % LLD Java class name: Main
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the same number line. Farmer John has two modes of transportation: Walking and teleporting.
*

POJ 3278 Catch That CowC-Catch That Cow
Crawling in process...Crawling failedTime Limit:2000 MSMemory Limit:65536KB64bit IO Format:% I64d % I64uSubmitStatus
Description
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and telep

]=step[a]+1;//The current number of steps equals the last step of +1;vis[flag]=1;//marked as 1;Q.push (flag);//queue; if(flag==n)//If the current value is n; returnStep[flag];//Returns the number of steps;} } }return 0;//If you are submitting C + +, do not return a value; //But if it is g++, a return 0 must be required; //This is a compiler problem, the specific is not very clear;}intMain () {intN,k;//k Chase N; while(~scanf("%d%d", k,n))//He

Problem-Solving ideas: Simple wide search, the key is pruning.1#include 2#include 3#include 4#include 5 using namespacestd;6 Const intMAXN =100005;7 intVIS[MAXN];//Mark whether this point has passed8 intN, K;9 Ten One structnode{ A intx, CNT; - }p, now; - theQueueQ; - - intBFsintXintCNT) - { +memset (Vis,0,sizeof(VIS));//initialized to never go through - while(!q.empty ()) Q.pop (); +p.x = x, p.cnt =CNT; A Q.push (p); at - while(!q.empty ()) - { -p =Q.front (); - Q.pop ();

Link: poke hereCatch that CowTime limit:2000ms Memory limit:65536kDescriptionFarmer John had been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0≤n≤100,000) on a number line and the cow are at a point K (0≤k≤100,000) on the same number Line. Farmer John has modes of transportation:walking and teleporting.* WALKING:FJ can move from any point x to the points X-1 or X + 1 inch a single minute* TELEPORTING:FJ can move from any point X to the p

200,000 AC. However, the running time is more than 2000 MS, it feels Java is really much slower than C + +.Java AC CodeImportjava.util.LinkedList;ImportJava.util.Queue;ImportJava.util.Scanner; Public classMain {StaticqueueNewLinkedlist(); Static intmax = 200010; Static BooleanMarked[] =New Boolean[Max]; Static intSteps[] =New int[Max]; Static intBoy , Cow; Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); Boy=Sc.nextint (); Cow=Sc.nextint (); BFS (); System.o

Topic Link: Catch that CowResolution: two numbers n and K, three operations: + 1,-1, * *, q, n at least how many times the operation can be equal to K.The simplest BFS template has, noteCondition of +1: x+1 -1 conditions: x-1 >= 0Conditions: x AC Code:#include Copyright NOTICE: This article is sxk original article, reprint please attach this article link ^_^ POJ 3278 Catch that Cow (BFS)

the minimum amount of time is how much (also can be said to be the smallest number of steps)! Note that walking can move around, but teleport (that is, another way to move forward only), and then you use these three ways to the one-dimensional coordinates of the points in a wide search, the minimum number of steps to reach the end!The problem is different from the previous one is that the previous is in the two-dimensional plane on the wide search (there are different paths), find the shortest

Can think of a wide search to solve this problem is also enough Diao: wide search to the target node can be answered steps#include #include#includeusing namespacestd;structnode{intValue, Steps; Node (intNints): Value (N), Steps (s) {}};queueQue;intvisited[100000];intMain () {intN, K; Memset (visited,0,sizeof(visited)); CIN>>N>>K; Que.push (Node (N,0)); Visited[n]=1; while( !Que.empty ()) {Node Top=Que.front (); if(Top.value = =K) {coutEndl; Break; } if(top.value-1>=0 visited[top

http://poj.org/problem?id=3278From N, to both sides of the transfer, in order not to allow unlimited expansion of the number, limited to 2*k within,Attention cannot be limited to k, otherwise there is a lack of continuous use-1 of the results obtained#include POJ 3278 Catch that Cow BFS difficulty: 1

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.