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);
    }
  • 相关阅读:
    运营总监招聘-e袋洗招聘-拉勾网
    中国服饰行业十大趋势
    赢在形象力之色彩
    百度系统部 在 北京市海淀区西二旗首创空间大厦 招聘 Python-交付运维系统研发工程师
    时间规划师
    使用python/casperjs编写终极爬虫-客户端App的抓取-ZOL技术频道
    传统线下零售商已经过时了,细分电商领域的机会仍待挖掘 | 36氪
    艺术私学----免费摄影、绘画、时尚造型课程体验_豆瓣
    艺术私学------绘画免费体验课程_豆瓣
    艺术私学------绘画免费体验课程_豆瓣
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5856249.html
Copyright © 2011-2022 走看看