zoukankan      html  css  js  c++  java
  • Snuke's Coloring 2-1

    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

    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

    #include <bits/stdc++.h>
    using namespace std;
    int w,h,n;
    int x1,x2,y3,y4;
    int ans;
    int xx,yy,op;
    int main(){
        cin >> w >> h >> n;
         x2 = w;
         y4 = h;
        while(n--){
            cin >> xx >> yy >> op;
            if(op == 1) x1 = max(xx,x1);
            else if(op == 2) x2 = min(x2,xx);
            else if(op == 3) y3 = max(yy,y3);
            else y4 = min(yy,y4);
        }
        ans = (x2 - x1) * (y4 - y3);
        if((x1 >= x2) || (y3 >= y4)) cout << 0;
        else cout << ans;
    }
    
  • 相关阅读:
    初始JSON
    JS异步加载的三种方式
    JS之事件
    关于null == 0?返回false的问题
    JS之类型转换
    金融(一)
    使用var声明的变量 和 直接赋值并未声明的变量的区别
    POJ2594 Treasure Exploration
    POJ1422 Air Raid
    Codevs1922 骑士共存问题
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12301589.html
Copyright © 2011-2022 走看看