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 & ...
随机推荐
- js打印数组查看
alert() 是不能查看数组,对象的console.log(数组变量); 然后你用火狐的friebug 在控制台查看
- Hibernate 通过 Session 操纵对象
Session 概述 •Session 接口是 Hibernate 向应用程序提供的操纵数据库的最主要的接口, 它提供了基本的保存, 更新, 删除和加载 Java 对象的方法. •Session 具有 ...
- touch ImageView
package com.example.touchdemo; import android.os.Bundle;import android.app.Activity;import android.u ...
- MongoDB的C#驱动程序教程(译) 转
1.概述 本教程是10gen支持C#驱动程序MongoDB的介绍.假定您熟悉使用MongoDB,因此主要集中在如何使用C#访问MongoDB的. 它分为两个部分:C# 驱动程序 ,BSON图书馆.C# ...
- Linux下GCC的使用
1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...
- C++11的new concepts (move semantic)
MoveConstructible 和MoveAssignable MoveConstructible Specifies that an instance of the type can be mo ...
- 转:Java面试题集(51-70) http://blog.csdn.net/jackfrued/article/details/17403101
Java面试题集(51-70) Java程序员面试题集(51-70) http://blog.csdn.net/jackfrued/article/details/17403101 摘要:这一部分主要 ...
- setLayoutParams getLayoutParams
继承关系:java.lang.Object ↳ android.view.ViewGroup.LayoutParams ↳ android.view.ViewGroup.MarginLayoutPar ...
- msf生成shellcode
msfpayload windows/exec CMD = calc.exe EXITFUNC=thread C 在kali Linux2.0新版中msfpayload命令已删除,功能已集成到msfv ...
- 如何实现标准TCODE的屏幕增强
如何实现标准TCODE的屏幕增强(HOWTO:Implement a screen exit to a standard SAP transaction) Introduction SAP provi ...