码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 738B Spotlights

时间:2017-02-14 13:51:05      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:ctime   logs   har   type   for   1.0   nbsp   pen   cst   

前缀和。

对于每个位置,求出四个方向的前缀和即可。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c))
    {
        x = x * 10 + c - 0;
        c = getchar();
    }
}

int t[1010][1010],s[1010][1010][4];
int n,m;

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) cin>>t[i][j];

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) s[i][j][0]=s[i][j-1][0]+t[i][j];

    for(int i=1;i<=n;i++)
        for(int j=m;j>=1;j--) s[i][j][1]=s[i][j+1][1]+t[i][j];

    for(int j=1;j<=m;j++)
        for(int i=1;i<=n;i++) s[i][j][2]=s[i-1][j][2]+t[i][j];

    for(int j=1;j<=m;j++)
        for(int i=n;i>=1;i--) s[i][j][3]=s[i+1][j][3]+t[i][j];

    int ans=0;

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(t[i][j]==0)
                for(int k=0;k<4;k++)
                    if(s[i][j][k]) ans++;
    cout<<ans<<endl;

    return 0;
}

 

CodeForces 738B Spotlights

标签:ctime   logs   har   type   for   1.0   nbsp   pen   cst   

原文地址:http://www.cnblogs.com/zufezzt/p/6397086.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!