codeforces 192 D
link: http://codeforces.com/contest/330/problem/D
The discription looks so long, but the problem is simple if you can grasp the problem quickly.
/*
ID: zypz4571
LANG: C++
TASK: 192d.cpp
*/ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime> #define INF 0x3f3f3f3f
#define REP(i, n) for(int i=0;i<int(n);++i)
#define FOR(i, a, b) for(int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for(int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for(int i=1;i<=int(n);++i)
#define mid int m=(l+r)/2
using namespace std;
int dir[][] = {{,-}, {, }, {-, }, {, }};
char mat[][];
struct Node {
int x, y, time;
};
Node start, end;
int ans, matime[][], n, m;
bool vis[][];
void bfs(Node end) {
queue<Node> q; q.push(end);
while (!q.empty()) {
Node tmp; tmp = q.front(); q.pop();
REP (i, ) {
int x, y;
x = tmp.x + dir[i][]; y = tmp.y + dir[i][];
if (x>= && x<n && y>= && y<m && mat[x][y] != 'T' && !vis[x][y]) {
Node t; t.x = x; t.y = y; t.time = tmp.time + ; matime[x][y] = t.time;
q.push(t); vis[x][y] = true;
}
}
}
}
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
cin>>n>>m;
memset(vis, false, sizeof(vis));
REP (i, n) {
cin>>mat[i];
REP (j, m) {
if (mat[i][j] == 'E') {
end.x = i, end.y = j; end.time = ;
vis[i][j] = true;
matime[i][j] = ;
} else if (mat[i][j] == 'S') {
start.x = i, start.y = j;
matime[i][j] = INF;
} else matime[i][j] = INF;
}
}
bfs(end);
int Time = matime[start.x][start.y], ans = ;
REP (i, n) {
REP (j, m) {
if (isdigit(mat[i][j]) && matime[i][j] != INF) {
if (Time >= matime[i][j]) ans += (mat[i][j]-'');
}
}
}
printf("%d\n", ans);
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
standard dfs
codeforces 192 D的更多相关文章
- [Codeforces #192] Tutorial
Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...
- codeforces 192 c
link: http://codeforces.com/contest/330/problem/C broute force but you must be careful about some tr ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs
B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- [Codeforces Round #192 (Div. 2)] D. Biridian Forest
D. Biridian Forest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #192 (Div. 2) (330B) B.Road Construction
题意: 要在N个城市之间修建道路,使得任意两个城市都可以到达,而且不超过两条路,还有,有些城市之间是不能修建道路的. 思路: 要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目 ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
随机推荐
- 数据结构-AVL树的旋转
http://blog.csdn.net/GabrieL1026/article/details/6311339 平衡二叉树在进行插入操作的时候可能出现不平衡的情况,AVL树即是一种自平衡的二叉树,它 ...
- java接收键盘输入
System.out.print("Please input String to check:");//提示输入 Scanner sc=new Scanner(System.in) ...
- root运行chrome
os:centos7 edit file : /usr/bin/google-chrome Add "--user-data-dir" (without the quotes) a ...
- a Makefile
obj-m += showpid.o obj-m += ps.o all: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) mo ...
- SharePoint安全 - 在Goolge和Bing中查找SharePoint相关内容
博客地址 http://blog.csdn.net/foxdave 本篇提供两个查询串字典,分别对应Google和Bing的搜索,用来查询SharePoint网站的相关内容 Google ShareP ...
- (五)CoreData 使用 (转)
第一次真正的使用CoreData,因此也会写下体会和心得...等有时间 Core Data数据持久化是对SQLite的一个升级,它是ios集成的,在说Core Data之前,我们先说说在CoreDat ...
- Android基础总结
原文 http://blog.csdn.net/heimady/article/details/10363995 1. 前言 1.1. 什么是 3G . 4G Ÿ 第三代移动通信技术(3rd - G ...
- 字符串常量演示Demo
public class StringDemo { public static void main(String[] args) { // TODO Auto-generated method stu ...
- 使用开源工具MonoDevelop开发GTK#图形界面
转自:http://developer.51cto.com/art/201011/235040.htm Mono一直到现在的2.8已经完全可以胜任一些比较小的项目了,但相关的开发文档与教程一直比较匮乏 ...
- Chapter 4: Tomcat Default Connector
一.概述 第三章介绍的connector是一个很好的学习工具,但是我们还可以做的更多.这一章介绍的是Tomcat4默认的connector. 一个Tomcat的connector是一个独立的模块,能够 ...