Spotlights
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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 40 1 0 01 0 1 0

output
9

input
4 40 0 0 01 0 0 10 1 1 00 1 0 0

output
20

Note

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.

分析:预处理前缀和,模拟;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define intxt freopen("in.txt","r",stdin)
const int maxn=1e3+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline ll read()
{ll x=0;int f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
int n,m,k,t,a[maxn][maxn],b[maxn][maxn];
ll ans;
int main()
{int i,j;scanf("%d%d",&n,&m);rep(i,1,n)rep(j,1,m)scanf("%d",&a[i][j]);rep(i,1,n)rep(j,1,m)b[i][j]=a[i][j];rep(i,1,n){rep(j,1,m){b[i][j]+=b[i][j-1];if(b[i][j]&&!a[i][j])ans++;}}rep(i,1,n)rep(j,1,m)b[i][j]=a[i][j];rep(i,1,n){for(j=m;j>=1;j--){b[i][j]+=b[i][j+1];if(b[i][j]&&!a[i][j])ans++;}}rep(i,1,n)rep(j,1,m)b[i][j]=a[i][j];rep(j,1,m){for(i=n;i>=1;i--){b[i][j]+=b[i+1][j];if(b[i][j]&&!a[i][j])ans++;}}rep(i,1,n)rep(j,1,m)b[i][j]=a[i][j];rep(j,1,m){rep(i,1,n){b[i][j]+=b[i-1][j];if(b[i][j]&&!a[i][j])ans++;}}printf("%lld\n",ans);//system("Pause");return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/6095586.html

Spotlights相关推荐

  1. ICLR2020放榜 34篇满分论文! 48篇orals,108篇spotlights,531篇poster

    点击上方"深度学习技术前沿",选择"星标"公众号 资源干货,第一时间送达 ICLR,全称为International Conference on Learnin ...

  2. VTK:灯光之SpotLights

    VTK:灯光之SpotLights VTK:灯光之SpotLights 描述 代码 SpotLights.cxx CMakeLists.txt VTK:灯光之SpotLights 描述 这个例子的地方 ...

  3. CVPR论文ORALS 、SPOTLIGHTS 、 POSTERS的区别

    粗暴且狭义的论文质量对比:ORALS > SPOTLIGHTS > POSTERS - ORALS: equivalent to the traditional CVPR orals. C ...

  4. 微软安全新闻聚焦-双周刊第三十四期

    Biweekly Spotlights ==== 2013. 6. 5– 2013. 6. 20  第 34 期 ==== 微软发布 EMET 4.0 2013年6月17日 Enhanced Miti ...

  5. ICLR2020放榜 687篇入选34篇得满分! 且看OpenReview数据图文详解

    深度学习的顶级会议ICLR 2020将于明年 4 月 26 日于埃塞俄比亚首都亚的斯亚贝巴举行. 今日ICLR 2020放榜,最终2594篇论文中共有687篇被接收,其中48篇orals,108篇sp ...

  6. NeurIPS2021 注意事项以及往年投稿、接受率回顾

    声明:本文来自AMiner,机器之心, NeurIPS2021官方网站等平台 NeurIPS2020 投稿量 首先从文章投稿量说,相对于2019年创纪录的投稿量6809,2020年再次刷新了新纪录,共 ...

  7. ICLR2020全析解读:华人学者占据60%,谷歌再次领跑!(附最新高引华人榜单)...

    关注上方"深度学习技术前沿",选择"星标公众号", 资源干货,第一时间送达! 来源:学术头条 ICLR 全称为 "International Conf ...

  8. 在场景中添加光线——在Deferred Shading引擎中添加阴影能力

    问题 虽然你已经掌握了基本的计算机实时光照,但你应该注意到光源还没有投射出阴影.这是因为pixel shader是基于光线与法线的夹角计算光照的.直到现在,pixel shader还没有考虑到光线与像 ...

  9. threejs 纹理流动_Threejs多重纹理与过程纹理实现

    Author--------------- Yen 多数时候同一图元是采用单一纹理,但是为了增强显示效果,会存在同一图元多个纹理图的情况,效果比如只有灯光照射的时候才会显示其他图案,其他没有被照射到的 ...

最新文章

  1. 使用javascript开发2048
  2. 高斯混合模型聚类实战(Gaussian Mixtures)
  3. p-unit - 单元级别开源性能测试框架
  4. QT学习:AxWidget界面显示
  5. 高手过招:用SQL解决环环相扣的刑侦推理问题(罗海雄版本)
  6. android 使用pdf文件大小,Android 加载PDF文件的使用
  7. 程序员最深情的告白——《致对象》
  8. STM32F103ZET6利用DAC产生噪声
  9. 【心路历程】(NOIP 206)(HNOI 358)
  10. 电力系统分析实验--生成节点导纳矩阵
  11. VSF表格 粘贴板ClipBoard 将数据粘贴到表格 VB6.0
  12. 飞凌小课堂-RK3399系列 linux双千兆网口解决方法-RTL8153
  13. vi修改文件格式编码(从dos改为unix)
  14. pt100铂电阻型号_铂热电阻型号(热电阻型号有什么表示)
  15. 区块链学习系列:对称与非对称加密区别?
  16. r语言r-shiny_如何使用R Shiny进行EDA和预测
  17. 域名纠错系统怎么解决
  18. 工控机和通用计算机相比的特点,工控机特点
  19. 微分代数几何基础(1)
  20. web组态可视化编辑器

热门文章

  1. FIREDAC连接SQLITE乱码的解决
  2. php生成excel范例,支持任意行列
  3. IE自动弹出窗口(JS/TrojanDownloader.Iframe.NDR 木马查杀)故障解决
  4. tomcat和apache的区别
  5. JS 的引用赋值与传值赋值
  6. 日常((⊙_⊙)…)
  7. Hadoop基础学习
  8. SpringMVC的上传和下载
  9. 银行科技管理工作优化提升之我见
  10. MD5算法之C#程序 MD5算法描述