炸一看好像很神仙的样子,其实就是个sb题 万年不见的1A

但是我们可以反过来想,先选一个起点到终点的联通块,然后这联通块后面相当于就能够走了,继续找联通块

然后就能发现直接相邻的脚步相同的边权为0,否则边权为1

直接bfs找最深的层就完事了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int _=1e2;
const int maxn=+_;
const int maxm=+_;
const int maxp=*+_;
const int dx[]={-,,,};
const int dy[]={,,,-};
int n,m;char mp[maxn][maxm]; int head,tail,d[maxn][maxm];
pair<int,int>list[*maxp];
void bfs()
{
int ans=;d[][]=;
head=maxp,tail=maxp;list[tail++]=make_pair(,);
while(head!=tail)
{
int x=list[head].first,y=list[head].second;head++;
ans=max(ans,d[x][y]);
for(int k=;k<=;k++)
{
int tx=x+dx[k],ty=y+dy[k];
if(tx>&&tx<=n&&ty>&&ty<=m&&mp[tx][ty]!='.'&&d[tx][ty]==)
{
int w=(mp[x][y]==mp[tx][ty])?:;
d[tx][ty]=d[x][y]+w;
if(w==)list[--head]=make_pair(tx,ty);
else list[tail++]=make_pair(tx,ty);
}
}
}
printf("%d\n",ans);
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%s",mp[i]+);
bfs(); return ;
}

bzoj3137: [Baltic2013]tracks的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. LA 4064 Magnetic Train Tracks

    题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...

  3. 11586 - Train Tracks

    Problem J: Train Tracks Andy loves his set of wooden trains and railroad tracks. Each day, Daddy has ...

  4. UVaLive 4064 Magnetic Train Tracks (极角排序)

    题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...

  5. 【BZOJ 3136】 3136: [Baltic2013]brunhilda (数论?)

    3136: [Baltic2013]brunhilda Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 238  Solved: 73[Submit][ ...

  6. 【BZOJ 3133】 3133: [Baltic2013]ballmachine (线段树+倍增)

    3133: [Baltic2013]ballmachine Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 148  Solved: 66 Descri ...

  7. Get just enough boost voltage - current-mirror circuit - VOUT tracks VIN varies

    Adding a current-mirror circuit to a typical boost circuit allows you to select the amount of boost ...

  8. LA 4064 (计数 极角排序) Magnetic Train Tracks

    这个题和UVa11529很相似. 枚举一个中心点,然后按极角排序,统计以这个点为钝角的三角形的个数,然后用C(n, 3)减去就是答案. 另外遇到直角三角形的情况很是蛋疼,可以用一个eps,不嫌麻烦的话 ...

  9. BZOJ_3133_[Baltic2013]ballmachine_堆+倍增

    BZOJ_3133_[Baltic2013]ballmachine_堆+倍增 Description 有一个装球机器,构造可以看作是一棵树.有下面两种操作: 从根放入一个球,只要下方有空位,球会沿着树 ...

随机推荐

  1. 使用HttpClient实现对第三方服务器的请求并接受返回数据

    /* * 创建日期 2017-4-7 * * TODO 要更改此生成的文件的模板,请转至 * 窗口 - 首选项 - Java - 代码样式 - 代码模板 */ package com.enfo.int ...

  2. 2013年EI收录的中国期刊

    ISSN 刊名 0567-7718 Acta Mechanica Sinica 1006-7191 Acta Metallurgica Sinica (English Letters) 0253-48 ...

  3. 无记录时显示gridview表头,并增加一行显示“没有记录”【绑定SqlDataSource控件时】

    原文发布时间为:2008-08-04 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  4. webstorm(二):拼写warning

    逼死强迫症之对拼写进行检查,警告 typo:in word “msgfromfather”

  5. Codeforces 616 E Sum of Remainders

    Discription Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the resu ...

  6. (入门SpringBoot)SpringBoot项目数据源以及整合mybatis(二)

    1.配置tomcat数据源: #   数据源基本配置spring.datasource.url=jdbc:mysql://localhost:3306/shoptest?useUnicode=true ...

  7. python学习笔记——递归算法

    阶乘 #递归计算阶乘 def factorial(n): if n == 1: return 1 return n*factorial(n-1) result = factorial(6) print ...

  8. influxdb的python操作

    1.先安装依赖:pip install influxdb 2.

  9. c++单元测试指南:使用google test

    Reference:http://www.codeproject.com/Articles/811934/Cplusplus-unit-test-start-guide-how-to-set-up-G ...

  10. 创建git仓库及简单操作命令

    1.把已有的项目代码纳入git管理 $ cd projectdir  #projectdir项目代码所在的文件夹 $ git init 2.新建的项目直接使用git管理 $ cd dir  #dir ...