ural 1250. Sea Burial
1250. Sea Burial
Memory limit: 64 MB
Input
Output
Samples
input | output |
---|---|
9 7 1 1 |
3 |
9 7 3 3 |
2 |
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
/**
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 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 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[] = {, -, , , -, , -, };
#define Land 1
#define Sea 2
int n, m, sx, sy;
int graph[N][N], mark[N][N];
int ans; inline void Input()
{
scanf("%d%d%d%d", &n, &m, &sx, &sy);
swap(sx, sy), swap(n, m);
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
{
char ch = ' ';
while(ch != '.' && ch != '#') ch = getchar();
graph[i][j] = ch == '.' ? Sea : Land;
}
} inline bool Check(int x, int y, int state)
{
if(x < || x > n || y < || y > m) return ;
if(!(graph[x][y] & state) || mark[x][y]) return ;
return ;
} inline void Draw(int sx, int sy, int state, int tag)
{
static int que[N * N][], tail;
mark[sx][sy] = tag;
tail = , que[][] = sx, que[][] = sy;
for(int head = ; head <= tail; head++)
{
int ux = que[head][], uy = que[head][];
for(int t = ; t < ; t++)
{
if(t > && graph[ux][uy] == Land) break;
int vx = ux + DX[t], vy = uy + DY[t];
if(!Check(vx, vy, state)) continue;
mark[vx][vy] = tag, tail++;
que[tail][] = vx, que[tail][] = vy;
}
}
} inline void Solve()
{
if(graph[sx][sy] == '#')
{
puts("");
return;
} Draw(sx, sy, Sea, );
for(int i = ; i <= n; i++)
{
Draw(i, , Land | Sea, );
Draw(i, m + , Land | Sea, );
}
for(int i = ; i <= m; i++)
{
Draw(, i, Land | Sea, );
Draw(n + , i, Land | Sea, );
} for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
if(!mark[i][j] && graph[i][j] == Land)
{
ans++;
Draw(i, j, Land, );
} printf("%d\n", ans);
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1250. Sea Burial的更多相关文章
- Ural 1250 Sea Burial 题解
目录 Ural 1250 Sea Burial 题解 题意 输入 题解 程序 Ural 1250 Sea Burial 题解 题意 给定一个\(n\times m\)的地图,\(.\)为水,\(\#\ ...
- URAL 1250 Sea Burial 简单Floodfill
问这个人掉落的海域包含几个岛屿. 八方向相连为同一片海域,四方向相连为同一个岛屿.与边界相连的岛屿不算. 方法:在给定地图外面填充一圈".",从这个人掉落的地方开始进行floodf ...
- ural 1250
有点坑的dfs 看懂题应该就会做了 神圣海必然围成一个圈 dfs将神圣还外围的全部去掉 简单题 #include <cstdio> #include <cstring> ...
- URAL 1934 spfa算法
D - Black Spot Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- sea.js模块化编程
* 为什么要模块化? 解决文件依赖 解决命名冲突 ; var var2 = 2; function fn1(){ } function fn2(){ } return { fn1: fn1, fn2: ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 解决sea.js引用jQuery提示$ is not a function的问题
在使用sea.js的如下写法引用jQuery文件时, //main.jsdefine(function(require,exports,module){ var $ = require('jquery ...
- 模块化开发--sea.js
当你的网站开发越来越复杂的时候,会经常遇到一下问题吗?1.冲突2.性能3.依赖如果在多人开发或者是复杂的开发过程中会经常遇到这些问 题,就可以用模块化开发来解决.以上问题是如何产生的?1.冲突:如果你 ...
- sea.js 入门
上个月学了 require.js 现在顺便来学学 sea.js. 对比下这两种的区别,看自己喜欢哪个,就在接下来的项目中去使用它吧. seajs中的所有 JavaScript 模块都遵循 CMD 模块 ...
随机推荐
- mysql列类型
mysql三大列类型 整型 tinyint(占据空间:1个字节 存储范围 有符号 -128-127 无符号 0-255) smallint mediumint int big ...
- ASP.NET的Cookie和Session
HTTP属于应用层,HTTP协议一共有五大特点:1.支持客户/服务器模式;2.简单快速;3.灵活;4.无连接;5.无状态. 无状态HTTP协议是无状态的协议.一旦数据交换完毕,客户端与服务器端的连接就 ...
- 重温WCF之会话Session(九)
转载地址:http://blog.csdn.net/tcjiaan/article/details/8281782 每个客户端在服务器上都有其的独立数据存储区,互不相干,就好像A和服务器在单独谈话一样 ...
- Delphi中怎么结束线程(这个线程是定时执行的)(方案二)
上篇博客中提出了一个问题:怎么结束一个定时循环执行的线程,并给出了一个解决方案,但是又出现了一个问题,详细去参考上一篇博客. 然后出去撒了个尿,突然脑子里出现了一个想法(看来工作和思考久了,出去走走, ...
- Angular JS [Draft]
AngularJS应用是完全运行在客户端的应用.没有后端的支持,我们只能展示随页面一起加载进来的数据.AngularJS提供了几种方式从服务器端获取数据. $http服务 $http 封装了浏览器原生 ...
- IOS 100 - level2 Boss
创建第一个app, buid, run. 过程 1 首先是按照知乎上的推荐去看了传说中的公开课了.看到第二集的时候觉得有种回到大学听老师上课的感觉--昏昏欲睡. 代码是一门实践课程,我觉得自己实现点东 ...
- thinkphp 两表、三表联合查询
//两表联合查询 $Model = M('T1');$Model->join('left join t2 on t1.cid = t2.id')->select();// $list = ...
- JDBC之——一个单线程JDBC基类和一些注意事项
下面的一个DBase基类提供了一些jdbc的基本操作,配置文件的配置部分并不准确,只是在自己机器上的mysql中测试过.. 数据库的增删改方法中都在开始调用了getConnection方法,末尾调用了 ...
- 词法分析 after Coding
学习词法分析,认为词法分析很难. 虽然不懂,但是要完成作业. 去图书馆或者看书借鉴代码,修改错误,让代码正常运行. 学习词法分析后,了解到自己有很多的不足: 1.代码不是很熟练,课本知识不了解.知识面 ...
- DampView阻尼效果
阻尼效果即是图片向下拉动时会放大,松开会回弹 1.自定义一个DampView类,继承ScrollView 2.布局最外层必须是DampView,且DampView和要拉动的图片之间只能有一层layou ...