bzoj3137: [Baltic2013]tracks
炸一看好像很神仙的样子,其实就是个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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- LA 4064 Magnetic Train Tracks
题意:给定平面上$n(3\leq n \leq 1200)$个无三点共线的点,问这些点组成了多少个锐角三角形. 分析:显然任意三点可构成三角形,而锐角三角形不如直角或钝角三角形容易计数,因为后者有且仅 ...
- 11586 - Train Tracks
Problem J: Train Tracks Andy loves his set of wooden trains and railroad tracks. Each day, Daddy has ...
- UVaLive 4064 Magnetic Train Tracks (极角排序)
题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...
- 【BZOJ 3136】 3136: [Baltic2013]brunhilda (数论?)
3136: [Baltic2013]brunhilda Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 238 Solved: 73[Submit][ ...
- 【BZOJ 3133】 3133: [Baltic2013]ballmachine (线段树+倍增)
3133: [Baltic2013]ballmachine Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 148 Solved: 66 Descri ...
- 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 ...
- LA 4064 (计数 极角排序) Magnetic Train Tracks
这个题和UVa11529很相似. 枚举一个中心点,然后按极角排序,统计以这个点为钝角的三角形的个数,然后用C(n, 3)减去就是答案. 另外遇到直角三角形的情况很是蛋疼,可以用一个eps,不嫌麻烦的话 ...
- BZOJ_3133_[Baltic2013]ballmachine_堆+倍增
BZOJ_3133_[Baltic2013]ballmachine_堆+倍增 Description 有一个装球机器,构造可以看作是一棵树.有下面两种操作: 从根放入一个球,只要下方有空位,球会沿着树 ...
随机推荐
- cf21D Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the ...
- Swift3.0 函数闭包与 Block
刚接触Swift,如有不对,欢迎指正 Swift中定义一个基本函数 //定义一个函数,接收一个字符串,返回一个String类型的值 func test(name:String) -> Strin ...
- N皇后-位运算优化
N皇后问题 时间限制: 5 Sec 内存限制: 128 MB 题目描述 魔法世界历史上曾经出现过一个伟大的罗马共和时期,出于权力平衡的目的,当时的政治理论家波利比奥斯指出:“事涉每个人的权利,绝不应 ...
- 【Codeforces Round #503 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9843198.html B:https://www.cnblogs.com/myx12345/p/9843245.html ...
- spring-基于注解的配置
基于注解的配置 除了采用采用xml来配置bean之外,也可以采用注解的方式来定义,注册,加载bean. 注解的方式在spring中默认时不开启的,所以需要在xml文件中进行配置启用 注解的启动方式有下 ...
- 关于gcc内置函数和c隐式函数声明的认识以及一些推测
最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候,你在代码里面引用了一个函数但是没有包含相关的头文件,这个 ...
- LeetCode OJ--Reverse Linked List II
http://oj.leetcode.com/problems/reverse-linked-list-ii/ 链表的操作 #include <iostream> using namesp ...
- BB FlashBack pro导出AVI格式的配置参数
文件-->导出,选择AVI格式在选择AVI解码器中选择Cinepak Codec by Radius压缩质量:建议6~12%点击确定在AVI导出选项中选择帧速率:4帧每秒音频选择格式 11.02 ...
- 升级python2至python3解决依赖关系
1.最小化安装centos7,在升级python3的时候会出现很多包未安装,为解决依赖关系: yum -y install gcc gcc-c++ zlib zlib-devel libffi-dev ...
- 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 ...