Hopscotch POJ 3050(搜索)

原题

题目链接

题目分析

bfs限制步数后爆搜就行了,答案用set维护(用来去重).

代码

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <utility>
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <cstring>
 7 #include <string>
 8 #include <vector>
 9 #include <stack>
10 #include <queue>
11 #include <map>
12 #include <set>
13
14 using namespace std;
15 typedef long long LL;
16 const int INF_INT=0x3f3f3f3f;
17 const LL INF_LL=0x3f3f3f3f3f3f3f3f;
18
19 struct G
20 {
21     int x,y,cnt,sum;
22 };
23
24 int grid[5][5];
25 set<int> ans;
26 int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
27 int res=0;
28
29 void bfs(int s,int t)
30 {
31     queue<G> que;
32     que.push((G){s,t,0,grid[s][t]});
33     while(que.size())
34     {
35         G g=que.front();que.pop();
36         if(g.cnt==5)
37         {
38             if(!ans.count(g.sum)) ans.insert(g.sum),res++;
39             continue;
40         }
41         for(int i=0;i<4;i++)
42         {
43             int nx=g.x+dx[i],ny=g.y+dy[i];
44             if(nx>=0&&nx<5&&ny>=0&&ny<5)
45             que.push((G){nx,ny,g.cnt+1,g.sum*10+grid[nx][ny]});
46         }
47     }
48 }
49
50 int main()
51 {
52 //    freopen("black.in","r",stdin);
53 //    freopen("black.out","w",stdout);
54     for(int i=0;i<5;i++)
55     for(int j=0;j<5;j++)
56     cin>>grid[i][j];
57     for(int i=0;i<5;i++)
58     for(int j=0;j<5;j++)
59     bfs(i,j);
60     cout<<res<<endl;
61     return 0;
62 } 

原文地址:https://www.cnblogs.com/VBEL/p/11396937.html

时间: 2024-08-01 21:29:39

Hopscotch POJ 3050(搜索)的相关文章

Hopscotch POJ - 3050

The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows create a 5x5 rectilinear grid of digits parallel to the x and y axes. They then adroitly hop onto any digit in

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids

poj 2531 搜索剪枝

Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description A university network is composed of N computers. System administrators gathered informat

poj 1129 搜索

Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description When a radio station is broadcasting over a very large area, repeaters are used to ret

POJ 3050 Hopscotch (穷竭搜索)

题目链接:http://poj.org/problem?id=3050 题面: Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2563   Accepted: 1823 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered

poj 3050 Hopscotch【搜索、去重】

点击打开题目 Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2126   Accepted: 1524 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cow

POJ 3050 Hopscotch 水~

http://poj.org/problem?id=3050 题目大意: 在一个5*5的格子中走,每一个格子有个数值,每次能够往上下左右走一格,问走了5次后得到的6个数的序列一共同拥有多少种?(一開始站的位置算一个,能够走回去) 思路: 近期我就是在做水题... 直接DFS就可以..我用map推断序列是否反复的. #include<cstdio> #include<cstring> #include<map> #include<string> #includ

Hopscotch(POJ 3050 DFS)

Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows creat

poj 3050 Hopscotch 【DFS】

Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2156   Accepted: 1548 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows creat