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;
}
Codeforces Round #380 (Div. 2)/729B Spotlights 水题的更多相关文章
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
随机推荐
- js经典试题之数组与函数
js经典试题之数组与函数 1:列举js的全局函数? 答案:JavaScript 中包含以下 7 个全局函数escape( ).eval( ).isFinite( ).isNaN( ).parseFlo ...
- mysql source 恢复 sql数据time_zone报错 已解决
报了一些变量的错误,类似于"time_zone" 等错误 解决: [root@iz8vbilqy0q9v8tds55bqzz conf.d]# vi /etc/my.cnf [my ...
- spring学习(一)——控制反转简单例子
spring框架是一个开源的轻量级的基于IOC与AOP核心技术的容器框架,主要是解决企业的复杂操作实现. 那IOC与AOP,到底如何解释呢,在看spring视频中,两个专业术语一定必须要懂得. IOC ...
- 如何重新安装Orchard CMS?
Orchard CMS安装后,配置文件和数据库保存在App_Data目录中.这个目录是受保护的,是不能通过网址访问到的. 如果要完全重装你的站点,你可以删除此目录中的所有文件,但是最好先备份!删除后重 ...
- lintcode-6-合并排序数组
合并排序数组 合并两个排序的整数数组A和B变成一个新的数组. 样例 给出A=[1,2,3,4],B=[2,4,5,6],返回 [1,2,2,3,4,4,5,6] 挑战 你能否优化你的算法,如果其中一个 ...
- 201621044079 week13 网络
作业13-网络 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以 ...
- 【Linux】- vi/vim
所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在. 但是目前我们使用比较多的是 vim 编辑器. vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正 ...
- 刚装的vs无法运行正确的程序
- windows网络模型
Windows提供了四种异步IO技术,机制几乎时相同的,区别在于通知结果的方式不同: 1.通过注册的消息函数进行通知 2.通过内核event事件进行通知 3.通过称为完成例程的回调函数进行通知 4.通 ...
- java计算某日期之后的日期
public static void main(String[] args) { // 时间表示格式可以改变,yyyyMMdd需要写例如20160523这种形式的时间 SimpleDateFormat ...