Codeforces 729B Spotlights 简单暴力
2016-11-30 21:08
260 查看
B. 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
output
input
output
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.
判断是否有1 我是利用加法,把1加起来,然后做差判断是否有1
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 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.
判断是否有1 我是利用加法,把1加起来,然后做差判断是否有1
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <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++) const int inf_int = 2e9; const long long inf_ll = 2e18; #define inf_add 0x3f3f3f3f #define mod 1000000007 #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, rt<<1 #define Rson mid+1, R, rt<<1|1 const int maxn=5e2+10; using namespace std; typedef long long ll; typedef unsigned long long ull; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1; while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-') fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48, rx=getchar();return ra*fh;} //#pragma comment(linker, "/STACK:102400000,102400000") 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;} int a[1005][1005]; int r[1005][1005]; int l[1005][1005]; int main() { ll re = 0; int n,m; cin >> n>> m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%I64d",&a[i][j]); r[i][j] = r[i-1][j]+a[i][j]; l[i][j] = l[i][j-1]+a[i][j]; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(a[i][j]==1) continue; if(r[i][j]!=0) re++; if(r [j]-r[i][j]!=0) re++; if(l[i][j]!=0) re++; if(l[i][m]-l[i][j]!=0) re++; } } printf("%I64d\n",re); return 0; }
相关文章推荐
- codeforces-16A-A. Flag (C && 简单模拟 && 暴力农夫山泉)
- CodeForces 740B Alyona and flowers 简单暴力
- codeforces 358A Dima and Continuous Line(思维简单,做法暴力)
- Codeforces 729A Interview with Oleg 简单暴力
- [codeforces] B. Parade 简单暴力
- CodeForces - 651B 一个简单的思考题,暴力也能过
- codeforces 358A Dima and Continuous Line(思维简单,做法暴力)
- CodeForces 292C Beautiful IP Addresses(简单搜索加大暴力乱搞)
- 简单的暴力搜索
- POJ 2856 Y2K Accounting Bug【简单暴力】
- URAL 1010 Discrete Function【简单暴力】
- CodeForces 120F - 简单的树形DP
- HDU 4681 string 求最长公共子序列的简单DP+暴力枚举
- 最简单的暴力求解算法 简单枚举
- CodeForces 128B - String 优先队列暴力..
- URAL 1010 Discrete Function【简单暴力】
- codeforces 283A - Cows and Sequence 简单数据结构模拟
- CodeForces 29D - Ant on the Tree 暴力LCA
- [专题]暴力之简单枚举
- codeforces 252B Unsorting Array 暴力+贪心