博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj4022
阅读量:6918 次
发布时间:2019-06-27

本文共 2338 字,大约阅读时间需要 7 分钟。

模拟

利用pick公式area=on/2+in-1

计算in的时候从外围广搜所有不是in的点,再用总数减去。

View Code
#include 
#include
#include
#include
#include
using namespace std;#define maxn 150struct Point{ int x, y;} q[maxn * maxn];char map[maxn][maxn];int n, m;bool vis[maxn][maxn];int dir[4][2] ={{ 1, 1 },{ 1, -1 },{ -1, 1 },{ -1, -1 } };int dir1[4][2] ={{ 1, 0 },{ 0, -1 },{ 0, 1 },{ -1, 0 } };void input(){ scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", map[i]);}bool out_of_bound(Point &a){ return a.x < 0 || a.y < 0 || a.x > n + 2 || a.y > m + 2;}bool ok(Point &a, Point &b){ int x = min(a.x, b.x) - 1; int y = min(a.y, b.y) - 1; if (x < 0 || y < 0 || x >= n || y >= m) return true; return map[x][y] == '.';}bool empty(int x, int y, char ch){ if (x < 0 || y < 0 || x >= n || y >= m) return true; return map[x][y] != ch;}bool on_the_bound(Point &a){ return !empty(a.x - 2, a.y - 2, '\\') || !empty(a.x - 1, a.y - 1, '\\') || !empty(a.x - 1, a.y - 2, '/') || !empty(a.x - 2, a.y - 1, '/');}void work(){ memset(vis, 0, sizeof(vis)); vis[0][0] = true; int front, rear; front = rear = 0; Point a; a.x = a.y = 0; q[rear++] = a; int cnt = 1; while (front != rear) { a = q[front++]; for (int i = 0; i < 4; i++) { Point b; b.x = a.x + dir[i][0]; b.y = a.y + dir[i][1]; if (!out_of_bound(b) && !on_the_bound(b) && ok(a, b) && !vis[b.x][b.y]) { q[rear++] = b; vis[b.x][b.y] = true; cnt++; } b.x = a.x + dir1[i][0]; b.y = a.y + dir1[i][1]; if (!out_of_bound(b) && !on_the_bound(b) && !vis[b.x][b.y]) { q[rear++] = b; vis[b.x][b.y] = true; cnt++; } } } int on = n * m; for (int i = 0; i < n; i++) on -= count(map[i], map[i] + m, '.'); cnt += on; int in = (n + 3) * (m + 3) - cnt; int ans = on / 2 + in - 1; printf("%d\n", ans);}int main(){ //freopen("t.txt", "r", stdin); input(); work();}

转载于:https://www.cnblogs.com/rainydays/archive/2012/10/23/2735731.html

你可能感兴趣的文章
web前端开发分享-css,js深化篇
查看>>
在CentOS下安装tomcat并配置环境变量(改默认端口8080为8081)
查看>>
AgileEAS.NET平台开发案例-药店系统-需求分析
查看>>
[Android] adb 命令 dumpsys activity , 用来看 task 中的activity。 (uninstall virus)
查看>>
MyBatis简单使用和入门理解
查看>>
图片移动效果
查看>>
基于Web的Kafka管理器工具之Kafka-manager安装之后第一次进入web UI的初步配置(图文详解)...
查看>>
C# Winform反序列化复杂json字符串
查看>>
SilverLight:布局(1) Border(边框)对象、Grid(网格)对象
查看>>
MonoBehaviour.print和Debug.Log是同样的作用
查看>>
SAP 接口概述
查看>>
BW Delta (增量)更新方法 .
查看>>
5.2. WebRTC
查看>>
Java的注解机制——Spring自动装配的实现原理
查看>>
正式生产环境下hadoop集群的DNS+NFS+ssh免password登陆配置
查看>>
SQL Server数据库大型应用解决方案总结
查看>>
[Think]故事几则
查看>>
gettools.exe 已停止工作
查看>>
视频监控相关文章
查看>>
Linux驱动的编译与加载
查看>>