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 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.
**题意:**问每个0的四个方位里有几个是有1的,求出数量的和。
**思路:**题目要求宽松,基本想怎么写就怎么写...
/** @Date : 2016-11-20-17.59
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include<bits/stdc++.h>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+2000;
vector<int>row[1010],col[1010];
int mp[1010][1010];
int main()
{
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%d", &mp[i][j]);
if(mp[i][j] == 1)
{
row[i].push_back(j);
col[j].push_back(i);
}
}
}
LL ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(mp[i][j])
continue;
int l = 0, r = 0;
for(int k = 0; k < row[i].size(); k++)
{
if(row[i][k] > j && r == 0)
r = 1;
if(row[i][k] < j && l == 0)
l = 1;
if((l == r && l == 1 ) || (r == 1 && row[i][k] > i))
break;
}
ans += l + r;
l = r = 0;
for(int k = 0; k < col[j].size(); k++)
{
if(col[j][k] > i && r == 0)
r = 1;
if(col[j][k] < i && l == 0)
l = 1;
if((l == r && l == 1 )|| (r == 1 && col[j][k] > j))
break;
}
ans += l + r;
}
}
printf("%lld\n", ans);
return 0;
}
最新文章
- Entity Framework Core 1.1 升级通告
- 泛型:HashMap的用法--输入字母输出数目
- html5 css3中的一些笔记
- [转]java.lang.OutOfMemoryError: PermGen space及其解决方法
- 提高AdoQuery的速度
- WPF Step By Step 系列 - 开篇 &#183;
- updatepannel的使用
- 使用CLRMD编写一个自己的C#调试器
- COJ 1059 - Numeric Parity 位操作
- 【D3.V3.js系列教程】--(十二)坐标尺度
- 比列的数目更多,以便找到第一k小值
- 你的MongoDB Redis设置用户名密码了吗?看看shodan这款邪恶的搜索引擎吧!~
- EXCEL读写NPOI--导出功能
- laravel整合JWT遇到的问题及解决方案
- 通过git上传本地代码到github仓库
- SQL Server 之 子查询与嵌套查询
- gym101657 C
- 文件内容统计:对任意给定的.txt文件进行内容的字符数、行数、单词数进行统计
- 【Python】zip文件密码破解
- Hybrid App中原生页面 VS H5页面(分享)