zoukankan      html  css  js  c++  java
  • D

    Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line 
    5 8 7 10 
    specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10). 
    If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once. 

    InputThe input format is a series of lines, each containing 4 integers. Four -1's are used to separate problems, and four -2's are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle. 
    OutputYour output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line. 
    Sample Input

    5 8 7 10
    6 9 7 8
    6 8 8 11
    -1 -1 -1 -1
    0 0 100 100
    50 75 12 90
    39 42 57 73
    -2 -2 -2 -2

    Sample Output

    8
    10000

    数据太小了,直接暴力

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 
     5 using namespace std;
     6 
     7 bool mp[105][105];
     8 
     9 int main()
    10 {
    11     int a,b,c,d;
    12     memset(mp,0,sizeof(mp));
    13     while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF)
    14     {
    15         // 每一组结束,输出并更新
    16         if(a<0 || b<0 || c<0 || d<0)
    17         {
    18             int ans=0;
    19             for(int i=0;i<=100;++i)
    20             {
    21                 for(int j=0;j<=100;++j)
    22                 {
    23                     if(mp[i][j])
    24                     {
    25                         ++ans;
    26                     }
    27                 }
    28             }
    29             printf("%d
    ",ans);
    30             memset(mp,0,sizeof(mp));
    31             continue;
    32         }
    33         // 暴力覆盖
    34         if(a>c)
    35         {
    36             swap(a,c);
    37         }
    38         if(b>d)
    39         {
    40             swap(b,d);
    41         }
    42         for(int i=a;i<c;++i)
    43         {
    44             for(int j=b;j<d;++j)
    45             {
    46                 mp[i][j]=true;
    47             }
    48         }
    49     }
    50 
    51     return 0;
    52 }
  • 相关阅读:
    Oracle 分区索引
    linux中select网络通信
    AVL树,红黑树,B-B+树,Trie树原理和应用
    zoj1232Adventure of Super Mario(图上dp)
    怎样更改Linux中默认的openjdk为自己安装的JDK
    食用甜玉米:增进健康,老少皆宜
    设计模式【3】:抽象工厂【创建对象】
    centos 7 安装JDK (Linux安装jdk)
    微信支付v3开发(5) 扫码并输入金额支付
    微信支付v3开发(6) 收货地址共享接口
  • 原文地址:https://www.cnblogs.com/jishuren/p/12246027.html
Copyright © 2011-2022 走看看