poj 3050 Hopscotch

水题,顺带学个stl的set怎么用。

set用法

http://www.cnblogs.com/luosuo10/p/5479668.html

 1 #include <iostream>
 2 #include <set>
 3 #include <cstdio>
 4 using namespace std;
 5 int temp;
 6 set <int> s;
 7 int dx[]={0,0,-1,1};
 8 int dy[]={1,-1,0,0};
 9 int ma[10][10];
10 #define judge(x,y) 0<=x && x<5 && 0<=y && y<5
11 void  dfs(int x,int y,int n,int sum)
12 {
13     if(n==6)
14     {
15         s.insert(sum);
16         return  ;
17     }
18     sum=sum*10+ma[x][y];
19     for(int i=0;i<4;i++)
20     {
21         int fx=x+dx[i];int fy=y+dy[i];
22         if(judge(fx,fy))
23         {
24             dfs(fx,fy,n+1,sum);
25         }
26     }
27 }
28 int main()
29 {
30     s.clear();
31     for(int i=0;i<5;i++)
32         for(int j=0;j<5;j++)
33     {
34         cin>>ma[i][j];
35     }
36
37     for(int i=0;i<5;i++)
38         for(int j=0;j<5;j++)
39     {
40         temp=0;
41         dfs(i,j,0,0);
42     }
43     cout<<s.size()<<endl;
44     return 0;
45 }
时间: 2024-07-29 03:01:16

poj 3050 Hopscotch的相关文章

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 水~

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

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

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 DFS

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

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

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

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

POJ 3258- River Hopscotch(二分求最小值最大)

River Hopscotch Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3258 Appoint description:  System Crawler  (2015-05-27) Description Every year the cows hold an event featuring a peculiar version