zoukankan      html  css  js  c++  java
  • POJ 3050 Hopscotch

    Hopscotch
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3372   Accepted: 2325

    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 create a 5x5 rectilinear grid of digits parallel to the x and y axes.

    They then adroitly hop onto any digit in the grid and hop forward, backward, right, or left (never diagonally) to another digit in the grid. They hop again (same rules) to a digit (potentially a digit already visited).

    With a total of five intra-grid hops, their hops create a six-digit integer (which might have leading zeroes like 000201).

    Determine the count of the number of distinct integers that can be created in this manner.

    Input

    * Lines 1..5: The grid, five integers per line

    Output

    * Line 1: The number of distinct integers that can be constructed

    Sample Input

    1 1 1 1 1
    1 1 1 1 1
    1 1 1 1 1
    1 1 1 2 1
    1 1 1 1 1

    Sample Output

    15

    Hint

    OUTPUT DETAILS:
    111111, 111112, 111121, 111211, 111212, 112111, 112121, 121111, 121112, 121211, 121212, 211111, 211121, 212111, and 212121 can be constructed. No other values are possible.

    Source

     
     
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <vector>
    #include <functional>
    #include <string>
    #include <cstring>
    #include <queue>
    #include <set>
    #include <cmath>
    #include <cstdio>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false)
    #define TIE std::cin.tie(0)
    #define MIN2(a,b) (a<b?a:b)
    #define MIN3(a,b) (a<b?(a<c?a:c):(b<c?b:c))
    #define MAX2(a,b) (a>b?a:b)
    #define MAX3(a,b,c)  (a>b?(a>c?a:c):(b>c?b:c))
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INF = 0x3f3f3f3f;
    const double PI = 4.0*atan(1.0);
    
    int ans, board[10][10], a[10];
    int dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
    map<int, int> ma;
    void dfs(int x, int y,int t)
    {
        a[t] = board[x][y];
        if (t == 5){
            int tmp = 0;
            for (int i = 0; i < 6; i++){
                tmp *= 10; tmp += a[i];
            }
            if (!ma.count(tmp)){ ma[tmp] = 1; ans++; }
            return;
        }
        for (int i = 0; i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < 5 && 0 <= ny && ny < 5)
                dfs(nx, ny, t + 1);
        }
    }
    int main()
    {
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                scanf("%d", &board[i][j]);
        ans = 0;
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                dfs(i, j, 0);
        printf("%d
    ", ans);
    }
  • 相关阅读:
    Highways(prim)
    Help Me with the Game(模拟)
    Parencodings
    The Pilots Brothers' refrigerator
    解决Geany 编辑器无法导入matplotlib包问题
    解决pycharm中导入自定义模块提示出错问题
    解决Pycharm中单元测试未发现问题(No tests were found)
    matplotlib设置中文的的一种方式
    matplotlib入门
    matplotlib入门
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5856249.html
Copyright © 2011-2022 走看看