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 ...
随机推荐
- 继承下public,protected,private访问权限
C++中派生类对基类成员的访问形式主要有以下两种: 1.内部访问:由派生类中新增成员对基类继承来的成员的访问. 2.对象访问:在派生类外部,通过派生类的对象对从基类继承来的成员的访问.今天给大家介绍在 ...
- Codeforces Round #371 (Div. 2)(set\unique)
B. Filya and Homework time limit per test 1 second memory limit per test 256 megabytes input standar ...
- [插件]jQuery multiselect初始化及默认值修改
下载地址:http://pan.baidu.com/s/1dE2daSD 1.Jquery多选下拉列表插件jquery multiselect功能介绍及使用 http://www.jb51.net/a ...
- 【20140113】package 与 import
一个完整的java源程序应该包括下列部分: package语句: //该部分至多只有一句,必须放在源程序的第一句 import语句: public classDefinition: //公共类定义部分 ...
- 使用RMAN DUPLICATE...FROM ACTIVE DATABASE创建物理standby database
Applies to: Oracle Server - Enterprise Edition - Version 11.1.0.6 to 11.2.0.4 [Release 11.1 to 11.2] ...
- AOJ789 买酒
买酒 Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MBTotal Submission: 70 Submis ...
- Oracle里SID、SERVICE_NAME
本文仅用作备忘,无实际指导意义,逻辑略混乱. 1.命令show parameter name; SQL> show parameter name; NAME TYPE VALUE ------- ...
- javase基础笔记3——this关键字和内存图
什么是面向对象? 面向过程. 面向过程:解决一个问题的思路和方法以及步骤 面向对象:把一些具有相同特征的问题抽象成一个对象,用""""对象.方法()" ...
- HTML概况性介绍
HTML(HyperText Markup Language)汉语的意思是:超文本标记语言. ”超文本”是指.html页面内不仅仅可以包含文字,还可以包含图片.链接,甚至音乐.程序等非文字元素. “标 ...
- LayoutInflater(四)
如果说要按类型来划分的话,自定义View的实现方式大概可以分为三种,自绘控件.组合控件.以及继承控件.那么下面我们就来依次学习一下,每种方式分别是如何自定义View的. 一.自绘控件 自绘控件的意思就 ...