ural 1338. Automobiles
1338. Automobiles
Memory limit: 64 MB
Input
Output
Experiment #N: North: Rn, South: Rs, East: Re, West: Rw
Sample
input | output |
---|---|
10 5 |
Experiment #1: North: 0, South: 1, East: 0, West: 0 |
Problem Source: USU Championship 2004
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
const int Dx[] = {, -, , }, Dy[] = {, , -, };
const int Where[] = {, , , };
int m, n;
char Map[N][N];
typedef pair<int, int> II;
II Point[N * N], Que[N * N * ];
int Tot;
int Dp[N][N], Mark[N][N], Come[N][N]; inline void Input()
{
scanf("%d%d", &m, &n);
For(i, , n)
{
getchar();
scanf("%s", Map[i] + );
}
} inline bool Check(int x, int y)
{
if(x < || x > n || y < || y > m) return ;
if(Map[x][y] == '.') return ;
return ;
} inline void Bfs(int Stx, int Sty)
{
For(i, , n)
For(j, , m)
Dp[i][j] = INF, Mark[i][j] = Come[i][j] = -;
int Tx, Ty, Head = , Tail = ;
Rep(i, )
{
Tx = Stx + Dx[i];
Ty = Sty + Dy[i];
if(Check(Tx, Ty))
{
Dp[Tx][Ty] = ;
Mark[Tx][Ty] = i;
Come[Tx][Ty] = Where[i];
Que[++Tail] = mk(Tx, Ty);
}
} while(Head <= Tail)
{
II Now = Que[Head++];
int x = Now.ft, y = Now.sd;
Rep(i, )
{
Tx = x + Dx[i];
Ty = y + Dy[i];
if(Check(Tx, Ty))
{
if(Dp[Tx][Ty] > Dp[x][y] + ||
(Dp[Tx][Ty] == Dp[x][y] + && Come[Tx][Ty] > Where[i]))
{
Dp[Tx][Ty] = Dp[x][y] + ;
Mark[Tx][Ty] = Mark[x][y];
Come[Tx][Ty] = Where[i];
Que[++Tail] = mk(Tx, Ty);
}
}
}
}
} inline void Solve()
{
Ford(i, n, )
For(j, , m)
if(Map[i][j] == 'o')
Point[++Tot] = mk(i, j); int Opt, Ans[];
scanf("%d", &Opt);
For(Test, , Opt)
{
int x;
scanf("%d", &x);
Bfs(Point[x].ft, Point[x].sd); Rep(i, ) Ans[i] = ;
For(i, , Tot)
if(x != i && Mark[Point[i].ft][Point[i].sd] != -)
Ans[Mark[Point[i].ft][Point[i].sd]]++;
printf("Experiment #%d: North: %d, South: %d, East: %d, West: %d\n",
Test, Ans[], Ans[], Ans[], Ans[]);
}
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("A");
#endif
Input();
Solve();
return ;
}
ural 1338. Automobiles的更多相关文章
- [ACM训练] 算法初级 之 数据结构 之 栈stack+队列queue (基础+进阶+POJ 1338+2442+1442)
再次面对像栈和队列这样的相当基础的数据结构的学习,应该从多个方面,多维度去学习. 首先,这两个数据结构都是比较常用的,在标准库中都有对应的结构能够直接使用,所以第一个阶段应该是先学习直接来使用,下一个 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- ural 2068. Game of Nuts
2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
- ural 2066. Simple Expression
2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...
随机推荐
- Java实现带括号优先级的计算器
这个计算器不仅能够进行四则运算,还支持添加括号进行优先级计算,例如下面算式: 10+(2*16-20/5)+7*2=52 Java源代码: import java.awt.BorderLayout; ...
- Android -- java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
使用Bundle 的getParcelableArray 出现了以下错误: Class not found when unmarshallingjava.lang.ClassNotFoundExcep ...
- c# 扩展方法奇思妙用基础篇八:Distinct 扩展(转载)
转载地址:http://www.cnblogs.com/ldp615/archive/2011/08/01/distinct-entension.html 刚看了篇文章 <Linq的Distin ...
- Hadoop 苦旅(1)——准备以及Cygwin安装
安装篇: 安装是最基本的,也是最难的.俗话说的好,万事开头难啊!的确如此.刚开始,自己折腾,总会是这样那样的问题,也许一个小的问题,就要推倒了重来.我现在就将这几天(2014-2-16~2014-2- ...
- 图结构练习——最小生成树(kruskal算法(克鲁斯卡尔))
图结构练习——最小生成树 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 有n个城市,其中有些城市之间可以修建公路,修建不同的公 ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 6-01T-SQL中的运算符
算术运算符:+.-.*./.%. 赋值运算符:= 逻辑运算符:AND.OR.NOT. 比较运算符:>,<,<=,>=,<>.=,!=. 连接运算符:"+& ...
- linux中socket的理解
对linux中socket的理解 一.socket 一般来说socket有一个别名也叫做套接字. socket起源于Unix,都可以用“打开open –> 读写write/read –> ...
- Android JNI开发生成.h头文件问题(转)
在JNI开发中,首先要将建立的anroid类编译成.h文件,编译用到命令javah,由于第一次用,以前对java的编译过程也不怎么了解,所以走了好多弯路,网络没有对这一步的详细介绍,这里讲一下: 通过 ...
- 【转】Struts2国际化
原文章:http://www.cnblogs.com/hellokitty1/p/5083663.html 简单理解 国际化简称i18n,其来源是英文单词 internationalizati ...