• poj3050 Hopscotch


    思路:

    水题。

    实现:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <set>
     4 using namespace std;
     5 
     6 int a[5][5];
     7 int dx[4] = { 0, 1, 0, -1 };
     8 int dy[4] = { 1, 0, -1, 0 };
     9 bool vis[1000000];
    10 int now[6];
    11 void dfs(int x, int y, int d)
    12 {
    13     if (d == 6)
    14     {
    15         int tmp = 0;
    16         for (int i = 0; i < 6; i++)
    17         {
    18             tmp += now[i];
    19             if (i != 5)
    20                 tmp *= 10;
    21         }
    22         vis[tmp] = true;
    23         return;
    24     }
    25     for (int i = 0; i < 4; i++)
    26     {
    27         int nx = x + dx[i];
    28         int ny = y + dy[i];
    29         if (nx >= 0 && nx < 5 && ny >= 0 && ny < 5)
    30         {
    31             now[d] = a[nx][ny];
    32             dfs(nx, ny, d + 1);
    33         }
    34     }
    35 }
    36 int main()
    37 {
    38     for (int i = 0; i < 5; i++)
    39     {
    40         for (int j = 0; j < 5; j++)
    41         {
    42             cin >> a[i][j];
    43         }
    44     }
    45     for (int i = 0; i < 5; i++)
    46     {
    47         for (int j = 0; j < 5; j++)
    48         {
    49             dfs(i, j, 0);
    50         }
    51     }
    52     int cnt = 0;
    53     for (int i = 0; i <= 999999; i++)
    54     {
    55         if (vis[i])
    56             cnt++;
    57     }
    58     cout << cnt << endl;
    59     return 0;
    60 }
  • 相关阅读:
    vue proxy代理理解
    css样式鲜为人知的属性
    vue中实现元素选中互斥
    站长统计加载慢解决方法
    微信图片预览接口
    移动端兼容问题
    请求头和响应头
    清除缓存方法
    屏幕适配及rem
    清除多个定时器
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6582243.html
Copyright © 2020-2023  润新知