博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【47.76%】【Round #380B】Spotlights
阅读量:5046 次
发布时间:2019-06-12

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

time limit per test1 second

memory limit per test256 megabytes
inputstandard input
outputstandard output
Theater stage is a rectangular field of size n × m. The director gave you the stage’s plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight’s position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

there is no actor in the cell the spotlight is placed to;

there is at least one actor in the direction the spotlight projects.
Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

Output

Print one integer — the number of good positions for placing the spotlight.

Examples

input
2 4
0 1 0 0
1 0 1 0
output
9
input
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0
output
20
Note
In the first example the following positions are good:

the (1, 1) cell and right direction;

the (1, 1) cell and down direction;
the (1, 3) cell and left direction;
the (1, 3) cell and down direction;
the (1, 4) cell and left direction;
the (2, 2) cell and left direction;
the (2, 2) cell and up direction;
the (2, 2) and right direction;
the (2, 4) cell and left direction.
Therefore, there are 9 good positions in this example.

【题目链接】:

【题解】

设f[i][j][4]表示从这个点往4个方向是不是有表演者(这个点是empty的情况下);
然后用记忆化搜索搞一波;
具体点;
从一个为empty的点开始往4个方向搜actor;如果搜到了actor,或者在途中遇到另外一个empty的点f[i][j][当前方向]为true;则也可以返回true;否则返回false;
统计答案就好;
直接用int即可不用LL;
【完整代码】

#include 
using namespace std;const int MAXN = 1010;const int dx[4] = {
0,0,1,-1};const int dy[4] = {
1,-1,0,0};int n,m,ans = 0;int f[MAXN][MAXN][4];bool a[MAXN][MAXN];int can(int x,int y,int p){ if (x > n || y>m) return 0; if (x < 1 || y<1) return 0; if (f[x][y][p]!=-1) return f[x][y][p]; if (a[x][y]) return 1; f[x][y][p] = can(x+dx[p],y+dy[p],p); return f[x][y][p];}int main(){ // freopen("F:\\rush.txt","r",stdin); scanf("%d%d",&n,&m); for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) scanf("%d",&a[i][j]); memset(f,255,sizeof(f)); for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++) if (!a[i][j]) { for (int k = 0;k <= 3;k++) if (can(i,j,k)) ans++; } printf("%d\n",ans); return 0;}

转载于:https://www.cnblogs.com/AWCXV/p/7626967.html

你可能感兴趣的文章
U盘安装centos5.11笔记
查看>>
HO引擎近况20130227
查看>>
Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、phpMyAdmin
查看>>
evaluateScript--evaluatePopoverScript--区别
查看>>
用贪心法解找零钱问题
查看>>
Spring Cloud微服务笔记(二)Spring Cloud 简介
查看>>
zabbix自定义监控
查看>>
MyBatis中动态SQL语句完成多条件查询
查看>>
TCP的连接(三次握手)和释放(四次挥手)
查看>>
将本地项目提交github
查看>>
web-ctf随机数安全
查看>>
真实感海洋的绘制(一):基于统计学模型的水面模拟方法
查看>>
code1002 搭桥
查看>>
struts的增删改查
查看>>
数据结构之二叉树
查看>>
[POJ 1269]Intersecting Lines
查看>>
[BZOJ 2820]YY的GCD
查看>>
伪随机性
查看>>
构建高性能的ASP.NET应用(二)-性能优化演绎法
查看>>
Mysql表分区的利弊
查看>>