Spotlights
1 second
256 megabytes
standard input
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.
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.
Print one integer — the number of good positions for placing the spotlight.
2 4
0 1 0 0
1 0 1 0
9
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0
20
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.
分析:预处理前缀和,模拟;
代码:
#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+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';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,,n)rep(j,,m)scanf("%d",&a[i][j]);
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(i,,n)
{
rep(j,,m)
{
b[i][j]+=b[i][j-];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(i,,n)
{
for(j=m;j>=;j--)
{
b[i][j]+=b[i][j+];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(j,,m)
{
for(i=n;i>=;i--)
{
b[i][j]+=b[i+][j];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(j,,m)
{
rep(i,,n)
{
b[i][j]+=b[i-][j];
if(b[i][j]&&!a[i][j])ans++;
}
}
printf("%lld\n",ans);
//system("Pause");
return ;
}
Spotlights的更多相关文章
- Codeforces #380 div2 B(729B) Spotlights
B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 【Codeforces 738B】Spotlights
Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which act ...
- [CF738B]Spotlights(前缀和,模拟)
题目链接:http://codeforces.com/contest/738/problem/B 题意:问多少个0的方向,使得方向上至少有一个1. 四个方向统计一遍前缀和,向上向左正着记,向下向右倒着 ...
- Codeforces Round #380 (Div. 2)/729B Spotlights 水题
Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which act ...
- 【47.76%】【Round #380B】Spotlights
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Spotlights【思维+前缀和优化】
https://blog.csdn.net/mengxiang000000/article/details/53291883 原博客地址 http://codeforces.com/group/1 ...
- Unity 5 中的全局光照技术详解
貌似是某位好人翻译的 https://unity3d.com/cn/learn/tutorials/topics/graphics/unity-5-lighting-and-rendering#rd? ...
- Codeforces Round #380 (Div. 2) 总结分享
B. Spotlights 题意 有n×m个格子的矩形舞台,每个格子里面可以安排一个演员或聚光灯,聚光灯仅可照射一个方向(俯视,上下左右).若聚光灯能照到演员,则称为"good positi ...
- Unity 用户手册用户指南二维纹理 (Texture 2D)
http://www.58player.com/blog-2327-953.html 二维纹理 (Texture 2D) 纹理 (Textures) 使您的 网格 (Meshes).粒子 (Parti ...
随机推荐
- AnimatorController动画融合树
通过Unity动画状态机,能帮我们轻松处理转换各个动画片断,达到想要的效果,但是如果仅仅是一个个动画的硬生生的切换,那么看起来就非常突然,而不真实了,在质量要求比较高的游戏中,特别是动作游戏,我们就不 ...
- JavaScript加减计算方法和显示千分位
Math.formatFloat = function (f, digit) { var m = Math.pow(10, digit); return parseInt(f * m, 10) / m ...
- webapi中的扩展点
Extension Points Web API provides extension points for some parts of the routing process. Interface ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 2387 Til the Cows Come Home
求1到N的最短路 注意有重边 跑一遍dijkstra就行 /* *********************************************** Author :Sun Yuefeng ...
- chapter 14_1 环境
Lua将其所有的全局变量保存在一个常规的table中,称为“global environment”. Lua将环境table自身保存在一个全局变量_G中,_G._G等于 _G . 比如下面的代码打印出 ...
- NOIP2011-普及组复赛模拟试题-第一题-NBA总冠军
题目背景 Background 一年两度的期末考要到来了!! 题目描述 Description 又要到考试了,Ljw决定放松一下,就打开电视,看见了篮球赛,他立即想到了每年的NBA总冠军队伍.由 ...
- Table获取checkbox选中行数据
//检测勾选值 function checkEnter() { var Ivalue = ""; $("#dataTable tr").each(functio ...
- C# 将List中的数据导入csv文件中
//http://www.cnblogs.com/mingmingruyuedlut/archive/2013/01/20/2849906.html C# 将List中的数据导入csv文件中 将数 ...
- 移动前端不得不了解的HTML5 head 头标签(中下篇)
SEO 优化部分 页面标题<title>标签(head 头部必须) <title>your title</title> 页面关键词 keywor ...
- Mongodb 抛出异常:dbexit: really exiting now
删除 数据库文件夹下,的 _tmp 和 mongodb.lock 文件 , 重启即可.我的数据文件在 /data/mongo/data/ 下