欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AtCoder Beginner Contest 182----E. Akari

程序员文章站 2022-07-15 11:16:24
...

旧人旧事更值得怀念,或悲或喜每个人身上都承载着某一段时光,但是我会永远清澈永远疯狂永远浪漫。没有人能回到过去重新活过,但你我都可以从现在开始,决定我们未来的模样。
                                                                                                                                                                           ----喻言

 AtCoder Beginner Contest 182----E. Akari

 题解:将所有灯和墙都放到矩形中,然后逐行从左到右扫描一遍,再从右到左扫描一遍;逐列从上到下扫描一遍,再从下到上扫描一遍。最后统计亮着的格子即可(也就是大于0的格子数)。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <complex>
#include <iomanip>
#include <numeric>
#include<unordered_set>
#include <climits>//INT_100010n
#include <regex>
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define INF 0x7fffffff;
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
#define LL unsigned int
#define mod 1000000007
#define wc 1e-18
typedef long long ll;
using namespace std;
int h, w, n, m;
int x,y,jg;
int mp[1510][1510];
int main()
{
    cin >> h >> w >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        mp[x - 1][y - 1] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        mp[x - 1][y - 1] = -1;
    }
    for (int i = 0; i < h; i++)
    {
        bool fg = false;
        for (int j = 0; j < w; j++)
        {
            if (mp[i][j] == 1)
                fg = true;
            else if (mp[i][j] == -1)
                fg = false;
            else if (fg)
                mp[i][j] = 2;
        }
        fg = false;
        for (int j = w - 1; j >= 0; --j)
        {
            if (mp[i][j] == 1)
                fg = true;
            else if (mp[i][j] == -1)
                fg = false;
            else if (fg)
                mp[i][j] = 2;
        }
    }
    for (int j = 0; j < w; j++)
    {
        bool fg = false;
        for (int i = 0; i < h; i++)
        {
            if (mp[i][j] == 1)
                fg = true;
            else if (mp[i][j] == -1)
                fg = false;
            else if (fg)
                mp[i][j] = 2;
        }
        fg = false;
        for (int i = h - 1; i >= 0; --i)
        {
            if (mp[i][j] == 1)
                fg = true;
            else if (mp[i][j] == -1)
                fg = false;
            else if (fg)
                mp[i][j] = 2;
        }
    }
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if(mp[i][j]>0)
                jg++;
    cout << jg << endl;
}

 

相关标签: AtCoder