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 有一个装球机器,构造可以看作是一棵树.有下面两种操作: 从根放入一个球,只要下方有空位,球会沿着树 ...
随机推荐
- Spoj-ODDDIV Odd Numbers of Divisors
Given a positive odd integer K and two positive integers low and high, determine how many integers b ...
- pageContext,request,session,application生命周期
equest是封装client端(也就是用户通过browser)提交的请求数据和属性的对象. response是封装web server端响应数据和属性的对象. 我们经常会将pageContext.r ...
- java system.out.printf()的使用方法
package test; public class Main { public static void main(String[] args) { // 定义一些变量,用来格式化输出. double ...
- uva 11426 线性欧拉函数筛选+递推
Problem J GCD Extreme (II) Input: Standard Input Output: Standard Output Given the value of N, you w ...
- poj 3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6956 Accepted: 3436 Desc ...
- Android SurfaceView与View
SurfaceView介绍 SurfaceView是视图(View)的继承类,这个视图里面内嵌了一个专门用于绘制的Surface.你可以控制这个Surface的格式和尺寸,而SurfaceView控制 ...
- T2602 最短路径问题 codevs
http://codevs.cn/problem/2602/ 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 平面上有n个点(n& ...
- python多线程(三)
原文:http://www.cnblogs.com/tqsummer/archive/2011/01/25/1944771.html 一.Python中的线程使用: Python中使用线程有两种方式: ...
- 11.Java web—servlet
继承关系图 一般新新建servlet继承HttpServlet即可 Servlet接口提供了 ServletConfig提供了 HttpServletRequest接口 HttpServletResp ...
- Java并发编程-Executor框架(转)
本文转自http://blog.csdn.net/chenchaofuck1/article/details/51606224 感谢作者 我们在传统多线程编程创建线程时,常常是创建一些Runnable ...