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

原文地址:https://www.cnblogs.com/hao-tian/p/9084832.html

时间: 2024-10-06 21:44:30

Snuke's Coloring 2-1的相关文章

すぬけ君の塗り絵 / Snuke&#39;s Coloring AtCoder - 2068 (思维,排序,贡献)

Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1≤i≤N ) cell he painted is the cell at the ai-th row and bi-th column. Compute the following: For each inte

csp退役前的做题计划1(真)

csp退役前的做题计划1(真) 因为我太菜了,所以在第一次月考就会退役,还是记录一下每天做了什么题目吧. 任务计划 [ ] Z算法(Z Algorithm) 9.28 [x] ARC061C たくさんの数式 / Many Formulas [x] ARC061D すぬけ君の塗り絵 / Snuke's Coloring [x] ARC061E すぬけ君の地下鉄旅行 / Snuke's Subway Trip [x] ARC061F 3人でカードゲーム / Card Game for Three [

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

C - 4-adjacent Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement We have a sequence of length N, a=(a1,a2,-,aN). Each ai is a positive integer. Snuke's objective is to permute the element in a so that the following conditi

CF149D. Coloring Brackets[区间DP !]

不知道为什么居中了,先把代码放这 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=705,MOD=1e9+7; char s[N]; long long n,f[N][N][5][5]; int st[N],top=0,m[N]; void match(){ for(int i=1;i<=

ARC078 D.Fennec VS. Snuke(树上博弈)

题目大意: 给定一棵n个结点的树 一开始黑方占据1号结点,白方占据n号结点 其他结点都没有颜色 每次黑方可以选择黑色结点临近的未染色结点,染成黑色 白方同理. 最后谁不能走谁输. 题解: 其实简单想想就可以想明白. 黑方肯定要往通往白方的最短路延伸,白方也是这样. 因为这样每次你可以最大化可行动次数. 所以先以1为根,dfs一遍,然后找到路径. 模拟一下走路径的过程,路径走光了就比谁的可行动次数多(有点像围棋的气的感觉),输出结果就可以了 #include <iostream> #includ

Fennec VS. Snuke

Fennec VS. Snuke Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N−1 roads, each connecting two cells. Cell ai is adjac

poj1419Graph Coloring

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4379   Accepted: 1985   Special Judge Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the o

CF# 149 D Coloring Brackets(区间dp)

D - Coloring Brackets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 149D Description Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solut

page coloring小结

页着色是一种通过选择性物理页分配来实现把虚存映射到特定cache位置的软件方法. 最早引入页着色概念是在计算机体系结构,是为了解决地址别名问题引入的. 首先对cache是使用虚拟地址还是物理地址的问题,有很多讨论,而在使用虚拟地址时,存在一个问题叫做别名问题.所谓别名问题出现的原因就是操作系统和用户程序可能对同一个物理地址使用两种以上不同形式的虚拟地址来访问,这些地址被称作别名,他们会导致同一个数据在使用虚拟地址的cache中存在两个副本,如果其中一个数据被修改,那么另外一个就是错误的. 对于别