zoukankan      html  css  js  c++  java
  • [USACO5.2]Snail Trails

    嘟嘟嘟

    一道很水的爆搜题,然后我调了近40分钟……

    错误:输入数据最好用cin,因为数字可能不止一位,所以用scanf后,单纯的c[0]为字母,c[1]数字…………………………

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a, x) memset(a, x, sizeof(a))
    15 #define rg register
    16 typedef long long ll;
    17 typedef double db;
    18 const int INF = 0x3f3f3f3f;
    19 const db eps = 1e-8;
    20 const int maxn = 125;
    21 inline ll read()
    22 {
    23   ll ans = 0;
    24   char ch = getchar(), last = ' ';
    25   while(!isdigit(ch)) {last = ch; ch = getchar();}
    26   while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
    27   if(last == '-') ans = -ans;
    28   return ans;
    29 }
    30 inline void write(ll x)
    31 {
    32   if(x < 0) x = -x, putchar('-');
    33   if(x >= 10) write(x / 10);
    34   putchar(x % 10 + '0');
    35 }
    36 
    37 int n, m, a[maxn][maxn];
    38 char c;
    39 int v;
    40 
    41 const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
    42 int ans = 0;
    43 void dfs(int x, int y, int step, int dir)
    44 {
    45   //printf("!%d %d
    ", x, y);
    46   if(step > ans) ans = step;
    47   if(a[x + dx[dir]][y + dy[dir]] == 1)
    48     {
    49       a[x][y] = 2;
    50       dfs(x + dx[dir], y + dy[dir], step + 1, dir);
    51       a[x][y] = 1;
    52     }
    53   else if(!a[x + dx[dir]][y + dy[dir]])
    54     {
    55       for(int i = 0; i < 4; ++i)
    56     if(a[x + dx[i]][y + dy[i]] == 1 && ((i + dir) & 1))
    57       {
    58         a[x][y] = 2;
    59         dfs(x + dx[i], y + dy[i], step + 1, i);
    60         a[x][y] = 1;
    61       }
    62     }
    63 }
    64 
    65 int main()
    66 {
    67   n = read(); m = read();
    68   for(int i = 1; i <= m; ++i)
    69     {
    70       cin >> c >> v;
    71       a[c - 'A' + 1][v] = 1;
    72     }
    73   for(int i = 1; i <= n; ++i)
    74     for(int j = 1; j <= n; ++j) a[i][j] ^= 1;
    75   dfs(1, 1, 1, 0); dfs(1, 1, 1, 1);
    76   write(ans), enter;
    77   return 0;
    78 }
    View Code
  • 相关阅读:
    Linux 常见命令使用
    Spring Cloud学习03--OpenFeign基本使用
    Spring Cloud学习02--Ribbon基本使用
    Spring Cloud学习01--Eureka基本使用
    两个都不可对角化的矩阵判断相似
    利用相似转化研究对象
    分段函数的应用
    0820. Short Encoding of Words (M)
    0637. Average of Levels in Binary Tree (E)
    0160. Intersection of Two Linked Lists (E)
  • 原文地址:https://www.cnblogs.com/mrclr/p/9871661.html
Copyright © 2011-2022 走看看