【47.76%】【Round #380B】Spotlights
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.
【题目链接】:http://codeforces.com/contest/738/problem/B
【题解】
设f[i][j][4]表示从这个点往4个方向是不是有表演者(这个点是empty的情况下);
然后用记忆化搜索搞一波;
具体点;
从一个为empty的点开始往4个方向搜actor;如果搜到了actor,或者在途中遇到另外一个empty的点f[i][j][当前方向]为true;则也可以返回true;否则返回false;
统计答案就好;
直接用int即可不用LL;
【完整代码】
#include <bits/stdc++.h>
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;
}
【47.76%】【Round #380B】Spotlights的更多相关文章
- LeetCode:全排列II【47】
LeetCode:全排列II[47] 参考自天码营题解:https://www.tianmaying.com/tutorial/LC47 题目描述 给定一个可包含重复数字的序列,返回所有不重复的全排列 ...
- POJ 1518 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 1584 A Round Peg in a Ground Hole【计算几何=_=你值得一虐】
链接: http://poj.org/problem?id=1584 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- 【UOJ#76】【UR #6】懒癌(动态规划)
[UOJ#76][UR #6]懒癌(动态规划) 题面 UOJ 题解 神....神仙题. 先考虑如果是完全图怎么做... 因为是完全图,所以是对称的,所以我们只考虑一个有懒癌的人的心路历程. 如果只有一 ...
- 【codeforces】【比赛题解】#851 CF Round #432 (Div.2)
cf真的难…… 点我浏览丧题. [A]Arpa和她对墨西哥人浪的研究 Arpa正在对墨西哥人浪进行研究. 有n个人站成一排,从1到n编号,他们从时刻0开始墨西哥人浪. 在时刻1,第一个人站起来.在时刻 ...
- 【BestCoder】【Round#41】
枚举+组合数?+DP+数学问题 http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=582 QAQ许久没打过比赛,来一发BC,结果还是只 ...
- 【Mail.Ru Cup 2018 Round 2 A】 Metro
[链接] 我是链接,点我呀:) [题意] [题解] 1:一直往右走的情况. 2:中间某个地方中转 (不会出现超过1次的转弯. (如果超过了和1次是等价的 [代码] #include <bits/ ...
- 【Mail.Ru Cup 2018 Round 2 B】 Alice and Hairdresser
[链接] 我是链接,点我呀:) [题意] [题解] 因为只会增加. 所以. 一开始暴力算出来初始答案 每次改变一个点的话. 就只需要看看和他相邻的数字的值就好. 看看他们是不是大于l 分情况增加.减少 ...
- 【Mail.Ru Cup 2018 Round 2 C】 Lucky Days
[链接] 我是链接,点我呀:) [题意] [题解] 题解的作者: manish_joshi 对于任意一个k 因为那条直线(关于x,y的方程可以看出一条直线)的斜率>= 所以肯定会经过第一象限. ...
随机推荐
- Can't access RabbitMQ web management interface after fresh install
http://stackoverflow.com/questions/22850546/cant-access-rabbitmq-web-management-interface-after-fres ...
- noi2019模拟测试赛(四十七)
noi2019模拟测试赛(四十七) T1与运算(and) 题意: 给你一个序列\(a_i\),定义\(f_i=a_1\&a_2\&\cdots\&a_i\),求这个序列的所 ...
- ZJOI2017线段树
ZJOI2017线段树 题意: 给你一颗广义线段树,太长了,自己去看. 题解: 直接上zkw那一套,把闭区间换成开区间,就是把取\([l,r]\),变成取\([l-1,l-1],[r+1,r+ ...
- Highcharts柱形范围图使用示例
功能需求:统计三种不同的状态在一天的时间段里面所占的范围 第一步:引入highcharts.js和highcharts-more.js文件 引入文件文件源码:下载https://img.hcharts ...
- Ubuntu 美团sql优化工具SQLAdvisor的安装(转)
by2009 by2009 发表于 3 个月前 SQLAdvisor简介 SQLAdvisor是由美团点评公司技术工程部DBA团队(北京)开发维护的一个分析SQL给出索引优化建议的工具.它基于MySQ ...
- 数据结构(C实现)------- 单链表
在单链表中,每个结点包括两部分:存放每个数据元素本身信息的数据域和存放其直接后继存储位置的指针域. 单链表结点的类型描写叙述: typedef int ElemType; typedef struct ...
- 「微信小程序」有哪些冲击与机会?
昨天晚上相信大家的朋友圈被「微信小程序」刷屏了,这影响力赶上了国务院出台新政策一样,足以说明微信在中国的影响力之大. 然后今天公号后台一大堆人问我怎么看这件事,不少人非常忧虑,仿佛自己将要失业一样. ...
- 关于我遇到的“LNK 2019无法解析的外部符号”的链接错误
昨天在调试程序的时候出现了"LNK 2019无法解析的外部符号"的问题(VS2008),依照网上说的方法都没有解决这个问题,最后在项目文件里发现有两个同名的可是不在同一个目录下的c ...
- 7lession-基础数据使用介绍
1.数值 这个使用比较简单 a = 1 b = 3.2 c = 12.5+4j d = 20L 2.字符串 代码 s = "hello world,i am comming" pr ...
- Flume的Events
Flume NG传输的数据的基本单位是event,如果是文本文件,通常是一行记录,这也是事务的基本单位.