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 & ...
随机推荐
- C++封装库
1.新建项目 -> Win32项目 选择DLL , 勾选 空项目 , 点击完成. 2.本例程,使用一个CPP文件 , 及一个头文件. 其中头文件包含函数声明,CPP文件实现函数声明. 3. ...
- wsgi协议
用来为server程序和app/framework程序做连接桥梁的,使server和app/framework各自发展,任意组合 上图是python3.4标准库里面,关于wsgiserver的实现.从 ...
- Java Bad version number in .class file
错误信息: java.lang.UnsupportedClassVersionError: Bad version number in .class file at java.lang.ClassLo ...
- CCNA 6.5
no sh (no shutdown : start the interface) router rspf 1 network x.x.x.x x.x.x.x area 0 int (interf ...
- PDF创建及动态转换控件程序包ActivePDF Portfolio
ActivePDF Portfolio是将4个activePDF最优秀的服务器产品捆绑成一个价格适中的控件程序包.它提供了开发一个完整的服务器端的PDF解决方案所需的一切. 具体功能: activeP ...
- greenDao 学习之坑 "java-gen" 目录下的类不能引用
由于公司最近的项目需要频繁地操作数据库,所以选用greenDao. 网上搜了一 大堆教程,我卡在java工程运行后生成的几个类不能引用了. 看了一下区别,教程的java-gen 目录是蓝色的小框框 , ...
- 预写式日志WAL
Chapter 25. 预写式日志(Write-Ahead Logging (WAL)) Table of Contents 25.1. WAL 的好处 25.2. WAL 配置 25.3. 内部 预 ...
- Nginx SSL配置过程
1. 在godaddy购买了UCC SSL(最多5个域名)的SSL证书 2. 设置证书 -- 管理 -- 3. 需要制作证书申请CSR文件(在线工具制作或者openssl命令制作),保存CSR和key ...
- IOS 中 NSArray
今天在做 cordova 关于处理未读条数的插件时,需要在js中传入 int 型. 但是发现所有插件 里面的参数信息都是封装在NSArry对象里面. 因此又突然想直接在NSArry获取信息的想法 ...
- HTML--5 JavaScript
一.JavaScript简介 1.JavaScript是个什么东西? 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它与Java什么关系? 没有什么直接的联系,Java是Sun公司 ...