[USACO5.2]Snail Trails
一道很水的爆搜题,然后我调了近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的更多相关文章
- 洛谷——P1560 [USACO5.2]蜗牛的旅行Snail Trails
P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...
- 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails(不明原因的scanf错误)
P1560 [USACO5.2]蜗牛的旅行Snail Trails 题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总 ...
- USACO 5.2 Snail Trails
Snail TrailsAll Ireland Contest Sally Snail likes to stroll on a N x N square grid (1 <n <= 12 ...
- [USACO5.2]蜗牛的旅行Snail Trails(有条件的dfs)
题目描述 萨丽·斯内尔(Sally Snail,蜗牛)喜欢在N x N 的棋盘上闲逛(1 < n <= 120). 她总是从棋盘的左上角出发.棋盘上有空的格子(用“.”来表示)和B 个路障 ...
- 洛谷 P1560 [USACO5.2]蜗牛的旅行Snail Trails
题目链接 题解 一看题没什么思路.写了个暴力居然可过?! Code #include<bits/stdc++.h> #define LL long long #define RG regi ...
- [题解]USACO 5.2.1 Snail Trails
链接:http://cerberus.delos.com:791/usacoprob2?S=snail&a=uzElkgTaI9d 描述:有障碍的棋盘上的搜索,求从左上角出发最多经过多少个格子 ...
- 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 ...
- CodeForces 209C Trails and Glades
C. Trails and Glades time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 dijkstra,堆,分层图
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1573 Solv ...
随机推荐
- Linux下模拟多线程的并发并发shell脚本
分享一个在Linux下模拟多线程的并发脚本,使用这个脚本可以同时批量在定义数量的服务器上执行相关命令,比起普通for/while循环只能顺序一条一条执行的效率高非常多,在管理大批服务器时非常的实用. ...
- CentOS7部署.Net Core2.0站点(上)
其实类似的教程网上已经有很多了,之所以要写,是应为发现在使用最新的centos7和.netcore2.1版本时还是遇到了不少坑,所以记录下,以后希望大家能少走弯路. 一.安装CentOS7 我是用虚拟 ...
- js实现浏览器窗口缩放刷新
两行代码 $(window).resize(function () { location.reload(); })
- org.apache.ibatis.binding.BindingException
1.异常提示: org.apache.ibatis.binding.BindingException: Mapper method 'com.artup.dao.WorksDao.selectWork ...
- 什么是APP???APP的开发类型又分哪几种???
开发者们都知道在高端智能手机系统中有两种应用程序: 一种是基于本地(操作系统)运行的APP —-Native App: 一种是基于高端机的浏览器运行的App —-WebApp因为这些高端智能手机(Ip ...
- npm属性笔记
scripts属性,运行脚本命令的npm命令行缩写,常见如下npm run devnpm run startnpm run build dependencies属性,项目运行时配置模块依赖的模块列表, ...
- css设置一行显示,超出部分显示...
碰到一些介绍时候需要一行显示,然后超出部分用...替代 white-space: nowrap;不换行显示text-overflow: ellipsis;以...显示overflow: hidden; ...
- eclipse插件开发常见的问题及解决办法
莫名其妙地我的某个Plug-in Projects出现了这样的Error:An API baseline has not been set for the current workspace.虽然后来 ...
- 动画演示10个有趣但毫无用处的Linux命令
Linux最强大的一个特征就是它有大量的各种小命令工具,这也可以称做是它最有趣的一个地方了.在这些大量的有用的命令和脚本中,你会发现有少部 分命令工具不那么有用的——如果你不愿意说是完全没用处的话.你 ...
- 01_Nginx入门
[Nginx概述] Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-Like协议下发行.其特点是占有内存少,并发能力强,事实上Nginx ...