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 ...
随机推荐
- 比较原声socket 、GCDAsyncSocket
原声socket NSInputStream 输入流(OC)NSOutputStream 输出流(OC)1:通过c语言的输入输出流CFReadStreamRef/CFWirteStreamRef(输入 ...
- lsof -ntP -i:端口取出 动行程序的PID 然后xargs kill -9 这个进程
[root@ok ok]# lsof -ntP -i: [root@ok ok]# netstat -lnutp|grep tcp /dnsmasq tcp /sshd tcp ::: :::* LI ...
- Android 5.0 如何正确启用isLoggable(一)__使用详解
转自:http://blog.csdn.net/yihongyuelan/article/details/46409389 isLoggable是什么 在Android源码中,我们经常可以看到如下代码 ...
- 【Java环境变量的配置问题】
首先是JVM.JRE.JDK三者之间的关系: java的跨平台性依赖于Java虚拟机:jvm(Java Virtual Machine),而jre(Java Runtime Environment,中 ...
- WinDbg 命令三部曲:(一)WinDbg 命令手册
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 系列博文 <WinDbg 命令三部曲:(一)WinDbg 命令手册> <WinDb ...
- HTTP/1.1 中 If-Modified-Since 和 If-Unmodified-Since 区别简记
接触HTTP/1.1的时日还不多, 有时候看着这两个参数老是有点混淆, 今天终于理清了, 现记录下. 初学网络, 若有理解不对, 还请拍砖. If-Modified-Since: 从字面上看, ...
- POJ3694 Network(Tarjan双联通分图 LCA 桥)
链接:http://poj.org/problem?id=3694 题意:给定一个有向连通图,每次增加一条边,求剩下的桥的数量. 思路: 给定一个无向连通图,添加一条u->v的边,求此边对图剩余 ...
- 学生成绩管理系统[C]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...
- Understanding Execution Governors and Limits
在编写Salesforce后台代码的时候,如果数据量比较大,或者需要与数据库的交互比较频繁的话,那么会抛出一些限制的异常,来提示你让你做进一步的修改. 有这些限制实质上是跟Salesforce是一个云 ...
- HDU 1561 The more, The Better 树形DP
The more, The Better Problem Description ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M ...