Snuke's Coloring 2-1

Posted zangzang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Snuke's Coloring 2-1相关的知识,希望对你有一定的参考价值。

问题 H: Snuke‘s Coloring 2-1

时间限制: 1 Sec  内存限制: 128 MB
提交: 141  解决: 59
[提交][状态][讨论版][命题人:admin]

题目描述

There is a rectangle in the xy-plane, with its lower left corner at (0,0) and its upper right corner at (W,H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1≤i≤N) point was (xi,yi).
Then, he created an integer sequence a of length N, and for each 1≤i≤N, he painted some region within the rectangle black, as follows:
If ai=1, he painted the region satisfying x<xi within the rectangle.
If ai=2, he painted the region satisfying x>xi within the rectangle.
If ai=3, he painted the region satisfying y<yi within the rectangle.
If ai=4, he painted the region satisfying y>yi within the rectangle.
Find the area of the white region within the rectangle after he finished painting.

Constraints
1≤W,H≤100
1≤N≤100
0≤xi≤W (1≤i≤N)
0≤yi≤H (1≤i≤N)
W, H (21:32, added), xi and yi are integers.
ai (1≤i≤N) is 1,2,3 or 4.

输入

The input is given from Standard Input in the following format:
W H N
x1 y1 a1
x2 y2 a2
:
xN yN aN

输出

Print the area of the white region within the rectangle after Snuke finished painting.
 

样例输入

5 4 2
2 1 1
3 3 4

样例输出

9

提示

The figure below shows the rectangle before Snuke starts painting.
技术分享图片
First, as (x1,y1)=(2,1) and a1=1, he paints the region satisfying x<2 within the rectangle:
技术分享图片
Then, as (x2,y2)=(3,3) and a2=4, he paints the region satisfying y>3 within the rectangle:
技术分享图片
Now, the area of the white region within the rectangle is 9.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int w,h,n;
    int x,y,t;
    cin>>w>>h>>n;
    int a[105][105]={0};
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>t;
        if(t==1)
        {
            for(int j=1;j<=x;j++)
            {
                for(int k=1;k<=h;k++)
                {
                    a[j][k] = 1;
                }
            }
        }
        else if(t==2)
        {
            for(int j=x+1;j<=w;j++)
            {
                for(int k=1;k<=h;k++)
                {
                    a[j][k] = 1;
                }
            }
        }
        else if(t==3)
        {
            for(int j=1;j<=w;j++)
            {
                for(int k=1;k<=y;k++)
                {
                    a[j][k] = 1;
                }
            }
        }
        else
        {
            for(int j=1;j<=w;j++)
            {
                for(int k=y+1;k<=h;k++)
                {
                    a[j][k] = 1;
                }
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=w;i++)
    {
        for(int j=1;j<=h;j++)
        {
            if(a[i][j]==0)
            {
                ans++;
            }
        }
    }
    cout<<ans;
}

数组运用






























以上是关于Snuke's Coloring 2-1的主要内容,如果未能解决你的问题,请参考以下文章

例题收藏◇例题·I◇ Snuke's Subway Trip

Atcoder Snuke's Subway Trip 重构图

[ARC061E]すぬけ君の地下鉄旅行 / Snuke's Subway Trip

AtCoder ARC061E Snuke's Subway Trip 最短路

Atcoder ABC 069 C - 4-adjacent D - Grid Coloring

Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring