• 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 ", ans);


    return 0;
    }

  • 相关阅读:
    Zookeeper白话解析
    WireMock简单使用
    mysql通用包安装
    修改mysql密码
    jmeter for循环嵌套if学习2
    jmeter for循环嵌套if学习1
    jmeter Transaction Controller学习
    jmeter ForEach Controller学习
    loadrunner随笔1
    shell中创建mysql库和执行sql脚本
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6083763.html
Copyright © 2020-2023  润新知