1. 程式人生 > >Snuke's Coloring 2-1

Snuke's Coloring 2-1

cst 時間 pri created some upper enc .cn OS

問題 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