嘟嘟嘟

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

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

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << ) + (ans << ) + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, m, a[maxn][maxn];
char c;
int v; const int dx[] = {, , , -}, dy[] = {, , -, };
int ans = ;
void dfs(int x, int y, int step, int dir)
{
//printf("!%d %d\n", x, y);
if(step > ans) ans = step;
if(a[x + dx[dir]][y + dy[dir]] == )
{
a[x][y] = ;
dfs(x + dx[dir], y + dy[dir], step + , dir);
a[x][y] = ;
}
else if(!a[x + dx[dir]][y + dy[dir]])
{
for(int i = ; i < ; ++i)
if(a[x + dx[i]][y + dy[i]] == && ((i + dir) & ))
{
a[x][y] = ;
dfs(x + dx[i], y + dy[i], step + , i);
a[x][y] = ;
}
}
} int main()
{
n = read(); m = read();
for(int i = ; i <= m; ++i)
{
cin >> c >> v;
a[c - 'A' + ][v] = ;
}
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) a[i][j] ^= ;
dfs(, , , ); dfs(, , , );
write(ans), enter;
return ;
}

[USACO5.2]Snail Trails的更多相关文章

  1. 洛谷——P1560 [USACO5.2]蜗牛的旅行Snail Trails

    P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...

  2. 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails(不明原因的scanf错误)

    P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...

  3. USACO 5.2 Snail Trails

    Snail TrailsAll Ireland Contest Sally Snail likes to stroll on a N x N square grid (1 <n <= 12 ...

  4. [USACO5.2]蜗牛的旅行Snail Trails(有条件的dfs)

    题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总是从棋盘的左上角出发.棋盘上有空的格子(用“.”来表示)和B 个路障 ...

  5. 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails

    题目链接 题解 一看题没什么思路.写了个暴力居然可过?! Code #include<bits/stdc++.h> #define LL long long #define RG regi ...

  6. [题解]USACO 5.2.1 Snail Trails

    链接:http://cerberus.delos.com:791/usacoprob2?S=snail&a=uzElkgTaI9d 描述:有障碍的棋盘上的搜索,求从左上角出发最多经过多少个格子 ...

  7. Codeforces 209 C. Trails and Glades

    Vasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails b ...

  8. CodeForces 209C Trails and Glades

    C. Trails and Glades time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  9. Bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 dijkstra,堆,分层图

    1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1573  Solv ...

随机推荐

  1. [转]如何在 .Net Framework 4.0 项目上使用 OData?

    本文转自:http://www.cnblogs.com/fiozhao/p/3536469.html 最新的 Microsoft ASP.NET Web API 2.1 OData 5.1.0 已只能 ...

  2. WES7 定制界面完整过程(去除所有windows标识)

    转载但有改动 红色字体记录 目的:实验从启动开始到出现桌面,不出现任何windows图标或标识.重大提示:在某些虚拟机上面操作和真实机器是不一样的,主机会容易很多;所以在虚拟机无法实现效果的时候使用主 ...

  3. SSH,SSM框架文件上传

    一.了解文件上传 1.1        什么是文件上传 将本地文件通过流的形式写到服务器上 1.2        文件上传的技术 JspSmartUpload: 其组件是应用jsp进行B/S程序开发过 ...

  4. 如何删除eclipse中已经保存的svn密码

    一.打开eclipse--->点击Window--->点击Perference,打开eclipse配置,输入svn,然后点击svn,找到下方svn接口,查看下svn是什么类型的接口,如果是 ...

  5. SQL语句整理(二) 数据定义语言DDL

    前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...

  6. 二 Channel

    Java NIO的通道类似流,但又有些不同 既可以从通道中读取数据,也可以写数据到通道.但是流的读写通常是单向的 通道可以异步读写 通道中的数据通常总是要先读到一个Buffer,或者总是从Buffer ...

  7. 基于Netty的NIO优化实践

    1. 浅谈React模型 2. Netty TCP 3. Netty UTP

  8. Effective C++ .44 typename和class的不同

    在C++模板中的类型参数一般可以使用typename和class,两者没有什么不同.但是typename比class多项功能: “任何时候当你想要在template中指涉一个嵌套从属类型名称,就必须在 ...

  9. 洛谷P3952 时间复杂度(模拟)

    题意 题目链接 Sol 咕了一年的题解..就是个模拟吧 考场上写的递归也是醉了... 感觉一年自己进步了不少啊..面向数据编程的能力提高了不少 #include<bits/stdc++.h> ...

  10. 使用JS完成注册表单的数据校验

    1.前台校验 防君子不防小人 JavaScript被设计用来向HTML页面添加交互行为 JavaScript是一种脚本语言(脚本语言是一种轻量级的编程语言) JavaScript由数行可执行计算机代码 ...